Documentation ¶
Index ¶
- type Backend
- type BaseComponent
- type BaseFanIn
- type BaseFanOut
- type BaseFiberType
- type BaseMultiRouteComponent
- type CachedPayload
- type Caller
- type Combiner
- type Component
- type ComponentKind
- type CtxKey
- type Dispatcher
- type EagerRouter
- type ErrorResponse
- func (resp *ErrorResponse) BackendName() string
- func (resp *ErrorResponse) IsSuccess() bool
- func (resp *ErrorResponse) Label(key string) []string
- func (resp *ErrorResponse) StatusCode() int
- func (resp *ErrorResponse) WithBackendName(backendName string) Response
- func (resp *ErrorResponse) WithLabel(key string, values ...string) Response
- func (resp *ErrorResponse) WithLabels(labels Labels) Response
- type FanIn
- type FanOut
- type Interceptor
- type Labels
- type LabelsMap
- type LazyRouter
- type MultiRouteComponent
- type NoopAfterCompletionInterceptor
- type NoopAfterDispatchInterceptor
- type NoopBeforeDispatchInterceptor
- type Proxy
- type Request
- type Response
- type ResponseQueue
- type Router
- type RoutingStrategy
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
Backend is an abstraction to be used for defining different backend endpoints for routers or combiners
func NewBackend ¶
NewBackend creates a new backend with the given name and endpoint
type BaseComponent ¶
type BaseComponent struct { BaseFiberType // contains filtered or unexported fields }
BaseComponent implements those contracts on the Component interface associated with the ID and Interceptors. Other network components can embed this type to re-use these methods.
func NewBaseComponent ¶
func NewBaseComponent(id string, kind ComponentKind) *BaseComponent
func (*BaseComponent) AddInterceptor ¶
func (c *BaseComponent) AddInterceptor(recursive bool, interceptors ...Interceptor)
AddInterceptor can be used to add one or more interceptors to the BaseComponent
func (*BaseComponent) ID ¶
func (c *BaseComponent) ID() string
ID is the getter for the BaseComponent's unique ID
func (*BaseComponent) Kind ¶
func (c *BaseComponent) Kind() ComponentKind
Kind is the getter for the type of the encompassing structure
type BaseFanIn ¶
type BaseFanIn struct {
BaseFiberType
}
BaseFanIn provides the default implementation for the Type interface
type BaseFanOut ¶
type BaseFanOut struct {
*BaseMultiRouteComponent
}
BaseFanOut is a component, that dispatches incoming request by each of its nested sub-routes
func NewFanOut ¶
func NewFanOut(id string) *BaseFanOut
NewFanOut initializes a new BaseFanOut component and assigns to it a generated unique ID and the list of nested children components
func (*BaseFanOut) Dispatch ¶
func (fanOut *BaseFanOut) Dispatch(ctx context.Context, req Request) ResponseQueue
Dispatch creates a copy of incoming request (one for each sub-route), asynchronously dispatches these request by its children components and then merges response channels into a single response channel with zero or more responseQueue in it
type BaseFiberType ¶
type BaseFiberType struct{}
BaseFiberType implements Type
func (BaseFiberType) Initialize ¶
func (b BaseFiberType) Initialize(_ json.RawMessage) error
Initialize is a dummy implementation for the Type interface
type BaseMultiRouteComponent ¶
type BaseMultiRouteComponent struct { BaseComponent // contains filtered or unexported fields }
BaseMultiRouteComponent is a reference implementation of a MultiRouteComponent
func NewMultiRouteComponent ¶
func NewMultiRouteComponent(id string) *BaseMultiRouteComponent
NewMultiRouteComponent is a factory function for creating a MultiRouteComponent
func (*BaseMultiRouteComponent) AddInterceptor ¶
func (multiRoute *BaseMultiRouteComponent) AddInterceptor(recursive bool, interceptors ...Interceptor)
AddInterceptor can be used to (optionally, recursively) add one or more interceptors to the BaseMultiRouteComponent
func (*BaseMultiRouteComponent) GetRoutes ¶
func (multiRoute *BaseMultiRouteComponent) GetRoutes() map[string]Component
GetRoutes is a getter for the routes configured on the BaseMultiRouteComponent
func (*BaseMultiRouteComponent) SetRoutes ¶
func (multiRoute *BaseMultiRouteComponent) SetRoutes(routes map[string]Component)
SetRoutes sets possible routes for this multi-route component
type CachedPayload ¶
type CachedPayload struct {
// contains filtered or unexported fields
}
CachedPayload caches []byte contents
func NewCachedPayload ¶
func NewCachedPayload(data []byte) *CachedPayload
NewCachedPayload is a creator factory for a CachedPayload structure
func (*CachedPayload) Payload ¶
func (b *CachedPayload) Payload() []byte
Payload returns the cached []byte contents
type Caller ¶
type Caller struct { BaseComponent // contains filtered or unexported fields }
Caller is the basic network component, that dispatches incoming request using configured transport-agnostic Dispatcher and asynchronously sends the response into an output channel
func NewCaller ¶
func NewCaller(id string, dispatcher Dispatcher) (*Caller, error)
NewCaller is a factory method that creates a new instance of Caller with given id and provided Dispatcher
func (*Caller) Dispatch ¶
func (c *Caller) Dispatch(ctx context.Context, req Request) ResponseQueue
Dispatch uses Dispatcher to process incoming request and asynchronously sends received response into the output channel. The output channel will be closed after Dispatcher has processed request and response was sent back
type Combiner ¶
type Combiner struct { BaseComponent FanOut // contains filtered or unexported fields }
Combiner is a network component, that uses BaseFanOut to dispatch incoming request by all of its sub-routes and then merge all the responseQueue from them into a single response, using provided FanIn
func NewCombiner ¶
NewCombiner is a factory for the Combiner type.
func (*Combiner) AddInterceptor ¶
func (c *Combiner) AddInterceptor(recursive bool, interceptor ...Interceptor)
AddInterceptor can be used to add the given interceptor to the Combiner and optionally, to all its nested components.
func (*Combiner) Dispatch ¶
func (c *Combiner) Dispatch(ctx context.Context, req Request) ResponseQueue
Dispatch method on the Combiner will ask its embedded dispatcher to simultaneously dispatch the incoming request by all of its nested components. After that, Combiner's FanIn listens to responseQueue and aggregate them into a single response, that is being sent to output
func (*Combiner) Kind ¶
func (c *Combiner) Kind() ComponentKind
Kind is the getter for the combiner's type
type Component ¶
type Component interface { Type // Returns component id ID() string // Returns the type of the encompassing structure, set at initialization Kind() ComponentKind // Dispatches the incoming request and returns a ResponseQueue // with zero or more responses in it Dispatch(ctx context.Context, req Request) ResponseQueue AddInterceptor(recursive bool, interceptors ...Interceptor) }
Component is the Base interface, that other network components should implement
type ComponentKind ¶
type ComponentKind string
ComponentKind can be used to define the types of Fiber components that support the Component interface
const ( // CallerKind represents a Fiber component that implements the Caller interface CallerKind ComponentKind = "Caller" // CombinerKind represents the Combiner type CombinerKind ComponentKind = "Combiner" // MultiRouteComponentKind represents a Fiber component that implements // the MultiRouteComponent interface MultiRouteComponentKind ComponentKind = "MultiRouteComponent" )
type CtxKey ¶
type CtxKey string
CtxKey is an alias for a string and is used to associate keys to context objects
var ( // CtxComponentIDKey is used to denote the component's id in the request context CtxComponentIDKey CtxKey = "CTX_COMPONENT_ID" // CtxComponentKindKey is used to denote the component's kind in the request context CtxComponentKindKey CtxKey = "CTX_COMPONENT_KIND" // CtxComponentLabelsKey is used to denote the component's labels in the request context CtxComponentLabelsKey CtxKey = "CTX_COMPONENT_LABELS" )
type Dispatcher ¶
type EagerRouter ¶
type EagerRouter struct {
*Combiner
}
EagerRouter implements Router interface and performs routing of incoming requests based on the routing strategy. The reason why it's 'eager' is because it dispatches incoming request by its every possible route in parallel and then returns either a response from a primary route (defined by the routing strategy) or switches back to one of fallback options.
In a sense, EagerRouter is a Combiner, that aggregates responses from its all routes into a single response by selecting this response based on a provided RoutingStrategy
func NewEagerRouter ¶
func NewEagerRouter(id string) *EagerRouter
NewEagerRouter initializes new EagerRouter
func (*EagerRouter) SetStrategy ¶
func (router *EagerRouter) SetStrategy(strategy RoutingStrategy)
SetStrategy sets routing strategy for this router
type ErrorResponse ¶
type ErrorResponse struct { *CachedPayload // contains filtered or unexported fields }
func (*ErrorResponse) BackendName ¶
func (resp *ErrorResponse) BackendName() string
func (*ErrorResponse) IsSuccess ¶
func (resp *ErrorResponse) IsSuccess() bool
func (*ErrorResponse) Label ¶ added in v0.2.0
func (resp *ErrorResponse) Label(key string) []string
func (*ErrorResponse) StatusCode ¶
func (resp *ErrorResponse) StatusCode() int
func (*ErrorResponse) WithBackendName ¶
func (resp *ErrorResponse) WithBackendName(backendName string) Response
func (*ErrorResponse) WithLabel ¶ added in v0.2.0
func (resp *ErrorResponse) WithLabel(key string, values ...string) Response
func (*ErrorResponse) WithLabels ¶ added in v0.2.0
func (resp *ErrorResponse) WithLabels(labels Labels) Response
type FanIn ¶
type FanIn interface { Type Aggregate(ctx context.Context, req Request, queue ResponseQueue) Response }
FanIn is the base interface for structural FanIn components, that is supposed to listen for zero or more incoming responseQueue from `in` and aggregates them into a single Response
type FanOut ¶
type FanOut interface { MultiRouteComponent }
FanOut is the base interface for structural FanOut Components, that is used to dispatch the incoming request simultaneously and asynchronously across all configured routes, writing the responseQueue, as available, to a single results channel.
type Interceptor ¶
type Interceptor interface { BeforeDispatch(ctx context.Context, req Request) context.Context AfterDispatch(ctx context.Context, req Request, queue ResponseQueue) AfterCompletion(ctx context.Context, req Request, queue ResponseQueue) }
Interceptor is the interface for a structural interceptor
type Labels ¶ added in v0.2.0
type Labels interface { Keys() []string Label(key string) []string WithLabel(key string, values ...string) Labels }
func NewLabelsMap ¶ added in v0.2.0
func NewLabelsMap() Labels
type LazyRouter ¶
type LazyRouter struct { *BaseMultiRouteComponent // contains filtered or unexported fields }
LazyRouter implements Router interface and performs routing of incoming requests based on the routing strategy. The reason why it's 'lazy' is because it tries to dispatch an incoming request by a primary route first and switches to fallback options (one by one) only if received response is not OK
func NewLazyRouter ¶
func NewLazyRouter(id string) *LazyRouter
NewLazyRouter initializes new LazyRouter
func (*LazyRouter) Dispatch ¶
func (r *LazyRouter) Dispatch(ctx context.Context, req Request) ResponseQueue
Dispatch makes a synchronous call to a routing strategy to select the primary route and fallbacks. After receiving a response it asynchronously asks a primary route to dispatch the request. If all responseQueue from a primary route are OK, it sends them back to output Otherwise it repeats the same with all fallback options one by one until one of fallbacks successfully dispatches a request or all fallbacks tried and failed to dispatch it
func (*LazyRouter) SetStrategy ¶
func (r *LazyRouter) SetStrategy(strategy RoutingStrategy)
SetStrategy sets routing strategy for this router
type MultiRouteComponent ¶
type MultiRouteComponent interface { Component SetRoutes(routes map[string]Component) GetRoutes() map[string]Component }
MultiRouteComponent - is a network component with zero or more possible routes, such as FanOut, Combiner, Router
type NoopAfterCompletionInterceptor ¶
type NoopAfterCompletionInterceptor struct{}
NoopAfterCompletionInterceptor does no operations after request completion
func (*NoopAfterCompletionInterceptor) AfterCompletion ¶
func (i *NoopAfterCompletionInterceptor) AfterCompletion(context.Context, Request, ResponseQueue)
AfterCompletion is an empty method
type NoopAfterDispatchInterceptor ¶
type NoopAfterDispatchInterceptor struct{}
NoopAfterDispatchInterceptor does no operations after dispatch
func (*NoopAfterDispatchInterceptor) AfterDispatch ¶
func (i *NoopAfterDispatchInterceptor) AfterDispatch(context.Context, Request, ResponseQueue)
AfterDispatch is an empty method
type NoopBeforeDispatchInterceptor ¶
type NoopBeforeDispatchInterceptor struct{}
NoopBeforeDispatchInterceptor does no operations before dispatch
func (*NoopBeforeDispatchInterceptor) BeforeDispatch ¶
func (i *NoopBeforeDispatchInterceptor) BeforeDispatch(ctx context.Context, req Request) context.Context
BeforeDispatch is an empty method
type Proxy ¶
type Proxy struct { Component // contains filtered or unexported fields }
Proxy can be used to configure an intermediary for requests
type Response ¶
type Response interface { IsSuccess() bool Payload() []byte StatusCode() int BackendName() string WithBackendName(string) Response Label(key string) []string WithLabel(key string, values ...string) Response WithLabels(Labels) Response }
func NewErrorResponse ¶
type ResponseQueue ¶
type ResponseQueue interface {
Iter() <-chan Response
}
func NewResponseQueue ¶
func NewResponseQueue(in <-chan Response, bufferSize int) ResponseQueue
NewResponseQueue takes an input channel and creates a Queue with all responseQueue from it
func NewResponseQueueFromResponses ¶
func NewResponseQueueFromResponses(responses ...Response) ResponseQueue
NewResponseQueueFromResponses takes list of responses and constructs an instance of ResponseQueue from them
type Router ¶
type Router interface { MultiRouteComponent // Sets routing strategy for this router SetStrategy(strategy RoutingStrategy) }
Router is a network component, that uses provided RoutingStrategy to select a route (child component), that should dispatch an incoming request
type RoutingStrategy ¶
type RoutingStrategy interface { Type // req - Incoming request (so the route can be selected based on the request) // routes - map of all possible routes SelectRoute(ctx context.Context, req Request, routes map[string]Component, ) (route Component, fallbacks []Component, labels Labels, err error) }
RoutingStrategy picks up primary route and zero or more fallbacks from the map of router routes
type Type ¶
type Type interface {
Initialize(cfgProperties json.RawMessage) error
}
Type interface provides a method to do custom initialization of fiber components