cqrs

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandEndpoint added in v1.2.5

func CommandEndpoint[C any](h CommandHandler[C]) endpoint.Endpoint[C, emptyResponse]

CommandEndpoint convert CommandHandler to Endpoint

func QueryEndpoint added in v1.2.5

func QueryEndpoint[Q any, R any](h QueryHandler[Q, R]) endpoint.Endpoint[Q, R]

QueryEndpoint convert QueryHandler to Endpoint

Types

type CommandHandler

type CommandHandler[C any] interface {
	Handle(ctx context.Context, cmd C) error
}

CommandHandler is a command handler that to update data. Commands should be task-based, rather than data centric. Commands may be placed on a queue for asynchronous processing, rather than being processed synchronously.

func ChainCommandHandler

func ChainCommandHandler[C any](handler CommandHandler[C], middlewares ...CommandMiddleware[C]) CommandHandler[C]

ChainCommandHandler decorates the given CommandHandler with all middlewares.

type CommandHandlerFunc

type CommandHandlerFunc[C any] func(ctx context.Context, cmd C) error

The CommandHandlerFunc type is an adapter to allow the use of ordinary functions as CommandHandler. If f is a function with the appropriate signature, CommandHandlerFunc(f) is a CommandHandler that calls f.

func (CommandHandlerFunc[C]) Handle

func (f CommandHandlerFunc[C]) Handle(ctx context.Context, cmd C) error

Handle calls f(ctx).

type CommandMiddleware added in v1.2.5

type CommandMiddleware[C any] interface {
	// Decorate wraps the underlying Command, adding some functionality.
	Decorate(handler CommandHandler[C]) CommandHandler[C]
}

CommandMiddleware allows us to write something like decorators to CommandHandler. It can execute something before Handle or after.

type CommandMiddlewareFunc added in v1.2.5

type CommandMiddlewareFunc[C any] func(handler CommandHandler[C]) CommandHandler[C]

The CommandMiddlewareFunc type is an adapter to allow the use of ordinary functions as CommandMiddleware. If f is a function with the appropriate signature, CommandMiddlewareFunc(f) is a CommandMiddleware that calls f.

func (CommandMiddlewareFunc[C]) Decorate added in v1.2.5

func (f CommandMiddlewareFunc[C]) Decorate(handler CommandHandler[C]) CommandHandler[C]

Decorate call f(cmd).

type NoopQuery added in v1.2.5

type NoopQuery[Q any, R any] struct{}

NoopQuery is an QueryHandler that does nothing and returns a nil error.

func (NoopQuery[Q, R]) Invoke added in v1.2.5

func (NoopQuery[Q, R]) Invoke(context.Context, Q) (R, error)

type QueryHandler

type QueryHandler[Q any, R any] interface {
	Handle(ctx context.Context, q Q) (R, error)
}

QueryHandler is a query handler that to queries to read data. Queries never modify the database. A query returns a DTO that does not encapsulate any domain knowledge.

func ChainQueryHandler

func ChainQueryHandler[Q any, R any](handler QueryHandler[Q, R], middlewares ...QueryMiddleware[Q, R]) QueryHandler[Q, R]

ChainQueryHandler decorates the given QueryHandler with all middlewares.

type QueryHandlerFunc

type QueryHandlerFunc[Q any, R any] func(ctx context.Context, q Q) (R, error)

The QueryHandlerFunc type is an adapter to allow the use of ordinary functions as QueryHandler. If f is a function with the appropriate signature, QueryHandlerFunc(f) is a QueryHandler that calls f.

func (QueryHandlerFunc[Q, R]) Handle

func (f QueryHandlerFunc[Q, R]) Handle(ctx context.Context, q Q) (R, error)

Handle calls f(ctx).

type QueryMiddleware added in v1.2.5

type QueryMiddleware[Q any, R any] interface {
	// Decorate wraps the underlying Command, adding some functionality.
	Decorate(QueryHandler[Q, R]) QueryHandler[Q, R]
}

QueryMiddleware allows us to write something like decorators to QueryHandler. It can execute something before Handle or after.

type QueryMiddlewareFunc added in v1.2.5

type QueryMiddlewareFunc[Q any, R any] func(QueryHandler[Q, R]) QueryHandler[Q, R]

The QueryMiddlewareFunc type is an adapter to allow the use of ordinary functions as QueryMiddleware. If f is a function with the appropriate signature, QueryMiddlewareFunc(f) is a QueryMiddleware that calls f.

func (QueryMiddlewareFunc[Q, R]) Decorate added in v1.2.5

func (f QueryMiddlewareFunc[Q, R]) Decorate(handler QueryHandler[Q, R]) QueryHandler[Q, R]

Decorate call f(cmd).

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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