courier

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 7 Imported by: 30

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{})

	err := TryCatch(func() {
		Run(RouterRoot, &FakeTransport{})
	})
	fmt.Println(err)
}
Output:

some thing wrong

Types

type Client

type Client interface {
	Do(operationID string, req interface{}, metas ...Metadata) Result
}

type ContextProvider

type ContextProvider interface {
	Operator
	ContextKey() string
}

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 MetatData

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 Operator

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

type OperatorMeta

type OperatorMeta struct {
	Type       reflect.Type
	ContextKey string
	Params     url.Values
	IsLast     bool
	Operator
}

func NewOperatorFactory

func NewOperatorFactory(op Operator, last bool) *OperatorMeta

func (*OperatorMeta) New

func (o *OperatorMeta) New() Operator

func (*OperatorMeta) String

func (o *OperatorMeta) String() string

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 []*OperatorMeta)

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(&OperatorB1{}, OperatorB2{}))

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

courier.OperatorA |> courier.OperatorA1?allowedRoles=ADMIN&allowedRoles=OWNER
courier.OperatorA |> courier.OperatorA2
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
}

Jump to

Keyboard shortcuts

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