courier

package
v0.0.0-...-a9eb721 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 10 Imported by: 5

Documentation

Overview

+gengo:runtimedoc=false

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextWithClient

func ContextWithClient(ctx context.Context, name string, client Client) context.Context

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 CanInjectContext

type CanInjectContext interface {
	InjectContext(ctx context.Context) context.Context
}

type Client

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

func ClientFromContext

func ClientFromContext(ctx context.Context, name string) Client

type ContextInjector

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

func ComposeContextWith

func ComposeContextWith(injectContexts ...ContextInjector) ContextInjector

type ContextProvider

type ContextProvider interface {
	Operator
	ContextKey() any
}

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 := []any{
	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

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) (any, error)
}

type OperatorFactory

type OperatorFactory struct {
	Type       reflect.Type
	ContextKey any
	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 OperatorNewer

type OperatorNewer interface {
	New() Operator
}

type OperatorWithParams

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

type OperatorWithoutOutput

type OperatorWithoutOutput interface {
	Operator
	NoOutput()
}

type Result

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

type Route

type Route interface {
	fmt.Stringer

	RangeOperator(each func(f *OperatorFactory, i int) error) error
}

type Router

type Router interface {
	Register(r Router)
	With(routers ...Router) Router
	Routes() Routes
}

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

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