courier

package module
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2022 License: MIT Imports: 9 Imported by: 10

README

Courier

GoDoc Widget Build Status codecov Go Report Card

Courier is micro framework inspired by Go kit

Documentation

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(router *Router, transports ...Transport)
Example
package main

import (
	"fmt"
)

type FakeTransport struct {
}

func (FakeTransport) UnmarshalOperator(op Operator) error {
	return nil
}

func (FakeTransport) Serve(router *Router) error {
	return fmt.Errorf("some thing wrong")
}

func main() {
	var RouterRoot = NewRouter(&EmptyOperator{})

	Run(RouterRoot, &FakeTransport{})
}
Output:

Types

type Client

type Client interface {
	Do(ctx context.Context, req interface{}, metas ...Metadata) Result
}

type ContextProvider

type ContextProvider interface {
	Operator
	ContextKey() interface{}
}

type ContextWith

type ContextWith = func(ctx context.Context) context.Context

func ComposeContextWith

func ComposeContextWith(contextWiths ...ContextWith) ContextWith

type DefaultsSetter

type DefaultsSetter interface {
	SetDefaults()
}

type EmptyOperator

type EmptyOperator struct {
	OperatorWithoutOutput
}

type Metadata

type Metadata map[string][]string
Example
metaA := Metadata{}
metaA.Add("A", "valueA1")
metaA.Add("A", "valueA2")

metaB := Metadata{}
metaB.Set("B", "valueB1")

metaAll := FromMetas(metaA, metaB)

results := []interface{}{
	metaAll.String(),
	metaAll.Has("A"),
	metaAll.Get("A"),
}

metaAll.Del("B")

results = append(results,
	metaAll.Get("B"),
	metaAll.String(),
)

for _, r := range results {
	fmt.Printf("%v\n", r)
}
Output:

A=valueA1&A=valueA2&B=valueB1
true
valueA1

A=valueA1&A=valueA2

func FromMetas

func FromMetas(metas ...Metadata) Metadata

merge metadata into one MetaData

func (Metadata) Add

func (m Metadata) Add(key, value string)

func (Metadata) Del

func (m Metadata) Del(key string)

func (Metadata) Get

func (m Metadata) Get(key string) string

func (Metadata) Has

func (m Metadata) Has(key string) bool

func (Metadata) Merge

func (m Metadata) Merge(metadata Metadata)

func (Metadata) Set

func (m Metadata) Set(key string, values ...string)

func (Metadata) String

func (m Metadata) String() string

type MetadataCarrier

type MetadataCarrier interface {
	Meta() Metadata
}

type MiddleOperators

type MiddleOperators []Operator

type Operator

type Operator interface {
	Output(ctx context.Context) (interface{}, error)
}

type OperatorFactory

type OperatorFactory struct {
	Type       reflect.Type
	ContextKey interface{}
	NoOutput   bool
	Params     url.Values
	IsLast     bool
	Operator   Operator
}

func NewOperatorFactory

func NewOperatorFactory(op Operator, last bool) *OperatorFactory

func (*OperatorFactory) New

func (o *OperatorFactory) New() Operator

func (*OperatorFactory) String

func (o *OperatorFactory) String() string

type OperatorInit

type OperatorInit interface {
	InitFrom(o Operator)
}

type OperatorMeta

type OperatorMeta = OperatorFactory

@deprecated

type OperatorWithParams

type OperatorWithParams interface {
	OperatorParams() map[string][]string
}

type OperatorWithoutOutput

type OperatorWithoutOutput interface {
	Operator
	NoOutput()
}

type Result

type Result interface {
	Into(v interface{}) (Metadata, error)
}

type Route

type Route struct {
	Operators []Operator
	// contains filtered or unexported fields
}

func (*Route) OperatorFactories

func (route *Route) OperatorFactories() (operatorFactories []*OperatorFactory)

func (*Route) String

func (route *Route) String() string

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router

func NewRouter

func NewRouter(operators ...Operator) *Router
Example
var RouterRoot = NewRouter(&EmptyOperator{})
var RouterA = NewRouter(&OperatorA{})
var RouterB = NewRouter(&OperatorB{})

RouterRoot.Register(RouterA)
RouterRoot.Register(RouterB)

RouterA.Register(NewRouter(&OperatorA1{}))
RouterA.Register(NewRouter(&OperatorA2{}))
RouterB.Register(NewRouter(&OperatorB2{}))

fmt.Println(RouterRoot.Routes())
Output:

courier.EmptyOperator |> courier.OperatorA |> courier.OperatorA1?allowedRoles=ADMIN&allowedRoles=OWNER
courier.EmptyOperator |> courier.OperatorA |> courier.OperatorA2
courier.EmptyOperator |> courier.OperatorB |> courier.OperatorB1 |> courier.OperatorB2

func (*Router) Register

func (router *Router) Register(r *Router)

Register child Router

func (*Router) Routes

func (router *Router) Routes() (routes Routes)

type Routes

type Routes []*Route

func (Routes) String

func (routes Routes) String() string

type Transport

type Transport interface {
	Serve(router *Router) error
}

type WithMiddleOperators

type WithMiddleOperators interface {
	MiddleOperators() MiddleOperators
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL