cqrs

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cqrs

Golang CQRS Framework

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEventHandler         = errors.New("cqrs: failed to handle event")
	ErrUnknownCommandType   = errors.New("cqrs: unknown command type")
	ErrUnknownQueryType     = errors.New("cqrs: unknown query type")
	ErrUnimplementedHandler = errors.New("cqrs: unimplemented handler")
	ErrPanicRecovered       = errors.New("cqrs: panic recovered")
)

Functions

This section is empty.

Types

type App

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

func New added in v1.2.0

func (*App) CommandBus added in v1.2.0

func (app *App) CommandBus() CommandBusPort

func (*App) EventBus added in v1.2.0

func (app *App) EventBus() EventBusPort

func (*App) HandleCommand

func (app *App) HandleCommand(t CommandType, f CommandHandlerFunc)

func (*App) HandleEvent

func (app *App) HandleEvent(t EventType, f EventHandlerFunc)

func (*App) HandleQuery

func (app *App) HandleQuery(t QueryType, f QueryHandlerFunc)

func (*App) QueryBus added in v1.2.0

func (app *App) QueryBus() QueryBusPort

func (*App) WithLogger added in v1.2.0

func (app *App) WithLogger(logger *slog.Logger) *App

type Command

type Command interface{ Type() CommandType }

Command

type CommandBus

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

func NewCommandBus

func NewCommandBus() *CommandBus

func (*CommandBus) Handle added in v1.2.0

func (cb *CommandBus) Handle(ctx context.Context, c Command) ([]Event, error)

Handle implements CommandHandler.

func (*CommandBus) HandleFunc

func (cb *CommandBus) HandleFunc(t CommandType, f CommandHandlerFunc)

HandleFunc implements CommandBusPort.

func (*CommandBus) WithLogger added in v1.2.0

func (cb *CommandBus) WithLogger(logger *slog.Logger) *CommandBus

type CommandBusPort added in v1.2.0

type CommandBusPort interface {
	CommandHandler
	HandleFunc(CommandType, CommandHandlerFunc)
}

CommandBus

type CommandController added in v1.2.0

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

func NewCommandController added in v1.2.0

func NewCommandController(bus CommandBusPort, decoders map[CommandType]CommandDecoder) *CommandController

func (*CommandController) Close added in v1.2.0

func (c *CommandController) Close() error

Close implements CommandController.

func (*CommandController) Commands added in v1.2.0

func (c *CommandController) Commands(w http.ResponseWriter, r *http.Request)

func (*CommandController) Metrics added in v1.2.0

func (c *CommandController) Metrics(w http.ResponseWriter, r *http.Request)

func (*CommandController) ServeHTTP added in v1.2.0

func (c *CommandController) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements CommandController.

func (*CommandController) Types added in v1.2.0

func (*CommandController) WithLogger added in v1.2.0

func (c *CommandController) WithLogger(logger *slog.Logger) *CommandController

type CommandDecoder added in v1.1.1

type CommandDecoder interface {
	DecodeCommand([]byte) (Command, error)
	CommandContentType() string
}

type CommandHandler

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

CommandHandler

type CommandHandlerFunc

type CommandHandlerFunc func(context.Context, Command) ([]Event, error)

CommandHandlerFunc

type CommandType

type CommandType string

CommandType

func (CommandType) String

func (ct CommandType) String() string

String

type Controller

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

func (*Controller) Close

func (c *Controller) Close() error

func (*Controller) ServeHTTP added in v1.2.0

func (c *Controller) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Event

type Event interface {
	Type() EventType
}

Event

type EventBus

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

func NewEventBus

func NewEventBus() *EventBus

func (*EventBus) Handle added in v1.2.0

func (eb *EventBus) Handle(ctx context.Context, e Event) error

Handle implements EventHandler.

func (*EventBus) HandleFunc

func (eb *EventBus) HandleFunc(t EventType, f EventHandlerFunc)

HandleFunc implements EventBusPort.

func (*EventBus) Types added in v1.2.0

func (eb *EventBus) Types() []EventType

Types implements [EventHandlerPort].

func (*EventBus) WithLogger added in v1.2.0

func (eb *EventBus) WithLogger(logger *slog.Logger) *EventBus

type EventBusPort added in v1.2.0

type EventBusPort interface {
	EventHandler
	HandleFunc(EventType, EventHandlerFunc)
}

EventBus

type EventController added in v1.2.0

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

func NewEventController added in v1.2.0

func NewEventController(bus EventBusPort, encoders map[EventType]EventEncoder) *EventController

func (*EventController) Close added in v1.2.0

func (e *EventController) Close() error

func (*EventController) Events added in v1.2.0

func (c *EventController) Events(w http.ResponseWriter, r *http.Request)

func (*EventController) Metrics added in v1.2.0

func (c *EventController) Metrics(w http.ResponseWriter, r *http.Request)

func (*EventController) ServeHTTP added in v1.2.0

func (c *EventController) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements EventController.

func (*EventController) Types added in v1.2.0

func (*EventController) WithConfig added in v1.2.0

func (c *EventController) WithConfig(config EventControllerConfig) *EventController

func (*EventController) WithLogger added in v1.2.0

func (c *EventController) WithLogger(logger *slog.Logger) *EventController

type EventControllerConfig added in v1.2.0

type EventControllerConfig struct {
	MaxEventBufferSize int
}

type EventEncoder added in v1.1.1

type EventEncoder interface {
	Encode(Event) ([]byte, error)
	EventContentType() string
}

type EventHandler

type EventHandler interface {
	Handle(context.Context, Event) error
}

EventHandler

type EventHandlerFunc

type EventHandlerFunc func(context.Context, Event) error

EventHandlerFunc

type EventType

type EventType string

EventType

func (EventType) String

func (et EventType) String() string

String

type Query

type Query interface{ Type() QueryType }

Query

type QueryBus

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

func NewQueryBus

func NewQueryBus() *QueryBus

func (*QueryBus) Handle added in v1.2.0

func (qb *QueryBus) Handle(ctx context.Context, q Query) (Result, error)

Handle implements QueryHandler.

func (*QueryBus) HandleFunc

func (qb *QueryBus) HandleFunc(t QueryType, f QueryHandlerFunc)

HandleFunc implements QueryBusPort.

func (*QueryBus) WithLogger added in v1.2.0

func (qb *QueryBus) WithLogger(logger *slog.Logger) *QueryBus

type QueryBusPort added in v1.2.0

type QueryBusPort interface {
	QueryHandler
	HandleFunc(QueryType, QueryHandlerFunc)
}

QueryBus

type QueryCodec added in v1.2.0

type QueryCodec interface {
	Decode([]byte) (Query, error)
	Encode(Result) ([]byte, error)
	ResultContentType() string
}

type QueryController added in v1.2.0

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

func NewQueryController added in v1.2.0

func NewQueryController(bus QueryBusPort, codecs map[QueryType]QueryCodec) *QueryController

func (*QueryController) Close added in v1.2.0

func (c *QueryController) Close() error

Close implements QueryController.

func (*QueryController) Metrics added in v1.2.0

func (c *QueryController) Metrics(w http.ResponseWriter, r *http.Request)

func (*QueryController) Queries added in v1.2.0

func (c *QueryController) Queries(w http.ResponseWriter, r *http.Request)

func (*QueryController) ServeHTTP added in v1.2.0

func (c *QueryController) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements QueryController.

func (*QueryController) Types added in v1.2.0

func (*QueryController) WithLogger added in v1.2.0

func (c *QueryController) WithLogger(logger *slog.Logger) *QueryController

type QueryHandler

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

QueryHandler

type QueryHandlerFunc

type QueryHandlerFunc func(context.Context, Query) (Result, error)

QueryHandlerFunc

type QueryType

type QueryType string

QueryType

func (QueryType) String

func (qt QueryType) String() string

String

type Result

type Result any

Result

type ResultEncoder added in v1.1.1

type ResultEncoder interface {
	Encode(Result) ([]byte, error)
}

type TraceID

type TraceID string

func Trace

func Trace(ctx context.Context) TraceID

func (TraceID) String

func (tid TraceID) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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