Documentation ¶
Overview ¶
Package eventrouter provides a router for events.
Package eventrouter provides a router for events.
Package eventrouter provides a router for events.
Index ¶
- Variables
- func GetSubjectFromContext(ctx context.Context) string
- func SaveSubjectToContext(ctx context.Context, subject string) context.Context
- type CorrelationIDProcessor
- type CorrelationIDProcessorOpt
- func CorrelationIDProcessorWithLogger(logger *zap.Logger) CorrelationIDProcessorOpt
- func CorrelationIDProcessorWithSkipStrategyCustom(sr map[string]map[string]struct{}) CorrelationIDProcessorOpt
- func CorrelationIDProcessorWithSkipStrategySkipAll() CorrelationIDProcessorOpt
- func CorrelationIDProcessorWithSkipStrategyUpdateOnly() CorrelationIDProcessorOpt
- type EventRouter
- type Handler
- type Middleware
- type Option
- type Router
- func (r *Router) Approve(subj string, handler Handler, middlewares ...Middleware)
- func (r *Router) Create(subj string, handler Handler, middlewares ...Middleware)
- func (r *Router) Delete(subj string, handler Handler, middlewares ...Middleware)
- func (r *Router) Deny(subj string, handler Handler, middlewares ...Middleware)
- func (r *Router) Process(ctx context.Context, subj string, event *govevents.Event) error
- func (r *Router) Revoke(subj string, handler Handler, middlewares ...Middleware)
- func (r *Router) Subjects() []string
- func (r *Router) Update(subj string, handler Handler, middlewares ...Middleware)
- func (r *Router) Use(mw Middleware)
Constants ¶
This section is empty.
Variables ¶
var ErrHandlerNotFound = errors.New("handler not found")
ErrHandlerNotFound is the error returned when a handler is not found
Functions ¶
func GetSubjectFromContext ¶
GetSubjectFromContext gets the subject from the context
Types ¶
type CorrelationIDProcessor ¶
type CorrelationIDProcessor struct {
// contains filtered or unexported fields
}
CorrelationIDProcessor is responsible for processing events based on correlation ID and skip strategy.
func NewCorrelationIDProcessor ¶
func NewCorrelationIDProcessor(opts ...CorrelationIDProcessorOpt) *CorrelationIDProcessor
NewCorrelationIDProcessor creates a new instance of CorrelationIDProcessor with the provided options.
func (*CorrelationIDProcessor) MWInjectCorrelationID ¶
func (p *CorrelationIDProcessor) MWInjectCorrelationID(next Handler) Handler
MWInjectCorrelationID returns a middleware that injects the correlation ID into the context.
func (*CorrelationIDProcessor) ShouldSkip ¶
func (p *CorrelationIDProcessor) ShouldSkip(cid, action, subj string) bool
ShouldSkip returns true if the event should be skipped based on the correlation ID and the skip strategy.
A process is only skipped when the correlation ID is not empty and the correlation ID is found in the history cache. The skip strategy is applied to determine if the event should be skipped.
type CorrelationIDProcessorOpt ¶
type CorrelationIDProcessorOpt func(*CorrelationIDProcessor)
CorrelationIDProcessorOpt is a function type for configuring CorrelationIDProcessor.
func CorrelationIDProcessorWithLogger ¶
func CorrelationIDProcessorWithLogger(logger *zap.Logger) CorrelationIDProcessorOpt
CorrelationIDProcessorWithLogger sets the logger for CorrelationIDProcessor.
func CorrelationIDProcessorWithSkipStrategyCustom ¶
func CorrelationIDProcessorWithSkipStrategyCustom(sr map[string]map[string]struct{}) CorrelationIDProcessorOpt
CorrelationIDProcessorWithSkipStrategyCustom sets a custom skip strategy for CorrelationIDProcessor.
func CorrelationIDProcessorWithSkipStrategySkipAll ¶
func CorrelationIDProcessorWithSkipStrategySkipAll() CorrelationIDProcessorOpt
CorrelationIDProcessorWithSkipStrategySkipAll sets the skip strategy to skip all events.
func CorrelationIDProcessorWithSkipStrategyUpdateOnly ¶
func CorrelationIDProcessorWithSkipStrategyUpdateOnly() CorrelationIDProcessorOpt
CorrelationIDProcessorWithSkipStrategyUpdateOnly sets the skip strategy to skip only update events.
type EventRouter ¶
type EventRouter interface { Create(string, Handler, ...Middleware) Update(string, Handler, ...Middleware) Delete(string, Handler, ...Middleware) Approve(string, Handler, ...Middleware) Deny(string, Handler, ...Middleware) Revoke(string, Handler, ...Middleware) Use(mw Middleware) Process(context.Context, string, *govevents.Event) error Subjects() []string }
EventRouter is an interface for an event router
type Middleware ¶
Middleware is a function type for defining middleware functions
type Option ¶
type Option func(*Router)
Option is a function that configures a Router
func WithCorrelationIDProcessor ¶
func WithCorrelationIDProcessor(p *CorrelationIDProcessor) Option
WithCorrelationIDProcessor configures the correlation ID processor for the Router
func WithLogger ¶
WithLogger configures the logger for the Router
func WithMiddleware ¶
func WithMiddleware(mw Middleware) Option
WithMiddleware configures the middleware for the Router
func WithTracer ¶
WithTracer configures the tracer for the Router
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router is the main router struct for mapping events to handlers
func (*Router) Approve ¶
func (r *Router) Approve(subj string, handler Handler, middlewares ...Middleware)
Approve adds a handler for the approve event
func (*Router) Create ¶
func (r *Router) Create(subj string, handler Handler, middlewares ...Middleware)
Create adds a handler for the create event
func (*Router) Delete ¶
func (r *Router) Delete(subj string, handler Handler, middlewares ...Middleware)
Delete adds a handler for the delete event
func (*Router) Deny ¶
func (r *Router) Deny(subj string, handler Handler, middlewares ...Middleware)
Deny adds a handler for the deny event
func (*Router) Revoke ¶
func (r *Router) Revoke(subj string, handler Handler, middlewares ...Middleware)
Revoke adds a handler for the revoke event
func (*Router) Subjects ¶
Subjects returns a list of subjects that have been registered with the router
func (*Router) Update ¶
func (r *Router) Update(subj string, handler Handler, middlewares ...Middleware)
Update adds a handler for the update event
func (*Router) Use ¶
func (r *Router) Use(mw Middleware)
Use adds a global middleware to the Router. This function can be used after the Router has been created.