eventrouter

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package eventrouter provides a router for events.

Package eventrouter provides a router for events.

Package eventrouter provides a router for events.

Index

Constants

This section is empty.

Variables

View Source
var ErrHandlerNotFound = errors.New("handler not found")

ErrHandlerNotFound is the error returned when a handler is not found

Functions

func GetSubjectFromContext

func GetSubjectFromContext(ctx context.Context) string

GetSubjectFromContext gets the subject from the context

func SaveSubjectToContext

func SaveSubjectToContext(ctx context.Context, subject string) context.Context

SaveSubjectToContext saves the subject to 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 Handler

type Handler func(context.Context, *govevents.Event) error

Handler is an function for processing governor events

type Middleware

type Middleware func(Handler) Handler

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

func WithLogger(logger *zap.Logger) Option

WithLogger configures the logger for the Router

func WithMiddleware

func WithMiddleware(mw Middleware) Option

WithMiddleware configures the middleware for the Router

func WithTracer

func WithTracer(tracer trace.Tracer) Option

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 NewRouter

func NewRouter(opts ...Option) *Router

NewRouter creates a new Router

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) Process

func (r *Router) Process(ctx context.Context, subj string, event *govevents.Event) error

Process function finds the event handler for the event and executes it

func (*Router) Revoke

func (r *Router) Revoke(subj string, handler Handler, middlewares ...Middleware)

Revoke adds a handler for the revoke event

func (*Router) Subjects

func (r *Router) Subjects() []string

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.

Jump to

Keyboard shortcuts

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