cqrs

package
v0.0.0-...-6b2826c Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: AGPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const ServiceName service.Name = "cqrs"

ServiceName defines the cqrs service name

Variables

View Source
var (
	ErrHandlerNotFound   = errors.New("handler not found")
	ErrUnexpectedRequest = errors.New("unexpected request")
	ErrUnexpectedData    = errors.New("unexpected data")
)

Functions

func ServiceProvider

func ServiceProvider() service.Provider

ServiceProvider returns a service.Provider for the the cqrs service

Types

type BaseCommand

type BaseCommand struct {
	// contains filtered or unexported fields
}

func NewBaseCommand

func NewBaseCommand(req CommandRequest) *BaseCommand

func (*BaseCommand) ID

func (c *BaseCommand) ID() CommandID

func (*BaseCommand) Request

func (c *BaseCommand) Request() CommandRequest

type BaseCommandResult

type BaseCommandResult struct {
	// contains filtered or unexported fields
}

func NewBaseCommandResult

func NewBaseCommandResult(cmd Command) *BaseCommandResult

func (*BaseCommandResult) Command

func (r *BaseCommandResult) Command() Command

type BaseQuery

type BaseQuery struct {
	// contains filtered or unexported fields
}

func NewBaseQuery

func NewBaseQuery(req QueryRequest) *BaseQuery

func (*BaseQuery) ID

func (q *BaseQuery) ID() QueryID

func (*BaseQuery) Request

func (q *BaseQuery) Request() QueryRequest

type BaseQueryResult

type BaseQueryResult struct {
	// contains filtered or unexported fields
}

func NewBaseQueryResult

func NewBaseQueryResult(qry Query, data interface{}) *BaseQueryResult

func (*BaseQueryResult) Data

func (r *BaseQueryResult) Data() interface{}

func (*BaseQueryResult) Query

func (r *BaseQueryResult) Query() Query

type Command

type Command interface {
	ID() CommandID
	Request() CommandRequest
}

type CommandFactory

type CommandFactory func(CommandRequest) (Command, error)

type CommandHandler

type CommandHandler interface {
	Handle(context.Context, Command) error
}

type CommandHandlerFunc

type CommandHandlerFunc func(context.Context, Command) error

func (CommandHandlerFunc) Handle

func (h CommandHandlerFunc) Handle(ctx context.Context, cmd Command) error

type CommandID

type CommandID string

type CommandMiddleware

type CommandMiddleware func(next CommandHandler) CommandHandler

type CommandRequest

type CommandRequest interface {
}

type CommandResult

type CommandResult interface {
	Command() Command
}

type CommandResultFactory

type CommandResultFactory func(Command) (CommandResult, error)

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

func From

func From(container *service.Container) (*Dispatcher, error)

From retrieves the cqrs service in the given container

func Must

func Must(container *service.Container) *Dispatcher

Must retrieves the cqrs service in the given container or panic otherwise

func NewDispatcher

func NewDispatcher(funcs ...OptionFunc) *Dispatcher

func (*Dispatcher) Exec

func (*Dispatcher) Query

func (d *Dispatcher) Query(ctx context.Context, req QueryRequest) (QueryResult, error)

func (*Dispatcher) RegisterCommand

func (d *Dispatcher) RegisterCommand(match MatchFunc, hdlr CommandHandler, mdlwrs ...CommandMiddleware)

func (*Dispatcher) RegisterQuery

func (d *Dispatcher) RegisterQuery(match MatchFunc, hdlr QueryHandler, mdlwrs ...QueryMiddleware)

type MatchFunc

type MatchFunc func(interface{}) (bool, error)

func MatchCommandRequest

func MatchCommandRequest(req interface{}) MatchFunc

func MatchQueryRequest

func MatchQueryRequest(req interface{}) MatchFunc

type Option

type Option struct {
	CommandFactory       CommandFactory
	QueryFactory         QueryFactory
	CommandResultFactory CommandResultFactory
	QueryResultFactory   QueryResultFactory
}

func CreateOption

func CreateOption(funcs ...OptionFunc) *Option

func DefaultOption

func DefaultOption() *Option

type OptionFunc

type OptionFunc func(*Option)

func WithBaseCommandFactory

func WithBaseCommandFactory() OptionFunc

func WithBaseCommandResultFactory

func WithBaseCommandResultFactory() OptionFunc

func WithBaseQueryFactory

func WithBaseQueryFactory() OptionFunc

func WithBaseQueryResultFactory

func WithBaseQueryResultFactory() OptionFunc

func WithCommandFactory

func WithCommandFactory(factory CommandFactory) OptionFunc

func WithQueryFactory

func WithQueryFactory(factory QueryFactory) OptionFunc

type Query

type Query interface {
	ID() QueryID
	Request() QueryRequest
}

type QueryFactory

type QueryFactory func(QueryRequest) (Query, error)

type QueryHandler

type QueryHandler interface {
	Handle(context.Context, Query) (interface{}, error)
}

type QueryHandlerFunc

type QueryHandlerFunc func(context.Context, Query) (interface{}, error)

func (QueryHandlerFunc) Handle

func (h QueryHandlerFunc) Handle(ctx context.Context, qry Query) (interface{}, error)

type QueryID

type QueryID string

type QueryMiddleware

type QueryMiddleware func(next QueryHandler) QueryHandler

type QueryRequest

type QueryRequest interface{}

type QueryResult

type QueryResult interface {
	Query() Query
	Data() interface{}
}

type QueryResultFactory

type QueryResultFactory func(Query, interface{}) (QueryResult, error)

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() *Registry

func (*Registry) MatchCommand

func (r *Registry) MatchCommand(cmd Command) (CommandHandler, []CommandMiddleware, error)

func (*Registry) MatchQuery

func (r *Registry) MatchQuery(qry Query) (QueryHandler, []QueryMiddleware, error)

func (*Registry) RegisterCommand

func (r *Registry) RegisterCommand(match MatchFunc, hdlr CommandHandler, mdlwrs ...CommandMiddleware)

func (*Registry) RegisterQuery

func (r *Registry) RegisterQuery(match MatchFunc, hdlr QueryHandler, mdlwrs ...QueryMiddleware)

Jump to

Keyboard shortcuts

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