Documentation
¶
Overview ¶
Package cqrs provides a lightweight, zero-allocation, thread-safe in-memory CQRS (Command Query Responsibility Segregation) and Event Streaming toolkit for Go.
Index ¶
- Variables
- type App
- type Command
- type CommandBusPort
- type CommandHandler
- type CommandHandlerFunc
- type CommandRegistry
- type CommandType
- type Event
- type EventBusPort
- type EventHandler
- type EventHandlerFunc
- type EventRegistry
- type EventSourcePort
- type EventStreamer
- type EventType
- type Projection
- type ProjectionBuilder
- type Query
- type QueryBusPort
- type QueryHandler
- type QueryHandlerFunc
- type QueryRegistry
- type QueryType
- type Result
Constants ¶
This section is empty.
Variables ¶
var ErrUnimplementedHandler = errors.New("cqrs: unimplemented handler")
ErrUnimplementedHandler - error value for unimplemented handler cases.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App interface {
CommandRegistry
CommandHandler
QueryRegistry
QueryHandler
EventRegistry
EventHandler
EventStreamer
ProjectionBuilder
io.Closer
}
App is the CQRS application facade interface.
type Command ¶
type Command interface {
Type() CommandType // Type returns [CommandType] value.
}
Command is the interface implemented by types that contains instructions for changing the state of the system (creating, updating, or deleting data).
type CommandBusPort ¶ added in v1.2.0
type CommandBusPort interface {
io.Closer
CommandHandler
CommandRegistry
}
CommandBusPort is the interface implemented by types that can route Command types to it's CommandHandlerFunc by it's CommandType value and implementing the CommandHandler interface to provide a single entry point for all commands.
type CommandHandler ¶
type CommandHandler interface {
// HandleCommand implements [CommandHandlerFunc] but without [Event] collection returning.
HandleCommand(context.Context, Command) error
}
CommandHandler is the interface implemented by types that can handle Command.
type CommandHandlerFunc ¶
CommandHandlerFunc is the type for functions that can handle Command and return Event collection. Returns non-nil [error] if Command cannot be handled.
type CommandRegistry ¶ added in v1.3.0
type CommandRegistry interface {
// OnCommand registers [CommandHandlerFunc] for [CommandType] value.
//
// Note: for composition root usage only, not for dynamic [CommandHandlerFunc] registration.
OnCommand(CommandType, CommandHandlerFunc)
}
CommandRegistry is the interface implemented by types that can register CommandHandlerFunc for CommandType value.
type CommandType ¶
type CommandType string
CommandType is the string alias for Command type declaration.
func (CommandType) String ¶
func (ct CommandType) String() string
String returns base CommandType string value.
type Event ¶
type Event interface {
Type() EventType // Type returns [EventType] value.
}
Event is the interface implemented by types that contains data describes system state changes.
type EventBusPort ¶ added in v1.2.0
type EventBusPort interface {
io.Closer
EventHandler
EventRegistry
}
EventBusPort is the interface implemented by types that can route Event types to it's EventHandlerFunc by it's EventType value and implementing the EventHandler interface to provide a single entry point for all events.
type EventHandler ¶
type EventHandler interface {
HandleEvent(context.Context, Event) // HandleEvent implements [EventHandlerFunc].
}
EventHandler is the interface implemented by types that can handle Event.
type EventHandlerFunc ¶
EventHandlerFunc is the type for "silent" functions that can handle Event.
type EventRegistry ¶ added in v1.3.0
type EventRegistry interface {
// OnEvent registers [EventHandlerFunc] for [EventType] value.
//
// Note: for composition root usage only, not for dynamic [EventHandlerFunc] registration.
OnEvent(EventType, EventHandlerFunc)
}
EventRegistry is the interface implemented by types that can register EventHandlerFunc for EventType value.
type EventSourcePort ¶ added in v1.4.0
type EventSourcePort interface {
io.Closer
EventHandler
EventStreamer
}
EventSourcePort is the interface implemented by types that can accept Event as EventHandler and broadcast it as EventStreamer.
type EventStreamer ¶ added in v1.3.0
EventStreamer is the interface implemented by types that can stream Event via channel.
type Projection ¶ added in v1.3.0
type Projection interface {
EventHandler
Types() []EventType // Types returns collection of [EventType] which [Projection] can handle.
}
Projection is the interface implemented by types that can collect and transform system Event or operational data into convenient, denormalized models optimized for fast reading. Projection is the polymorphic EventHandler with own Event routing.
type ProjectionBuilder ¶ added in v1.3.0
type ProjectionBuilder interface {
// Build registers [Projection.HandleEvent] method for each in [Projection.Types] [EventType] value.
Build(Projection)
}
ProjectionBuilder is the interface implemented by types that can register Projection for it's building.
type Query ¶
type Query interface {
Type() QueryType // Type returns [QueryType] value.
}
Query is the interface implemented by types that contains instructions for read-only operations without changes in system state.
type QueryBusPort ¶ added in v1.2.0
type QueryBusPort interface {
io.Closer
QueryHandler
QueryRegistry
}
QueryBusPort is the interface implemented by types that can route Query types to it's QueryHandlerFunc by it's QueryType value and implementing the QueryHandler interface to provide a single entry point for all queries.
type QueryHandler ¶
type QueryHandler interface {
HandleQuery(context.Context, Query) (Result, error) // HandleQuery implements [QueryHandlerFunc].
}
QueryHandler is the interface implemented by types that can handle Query.
type QueryHandlerFunc ¶
QueryHandlerFunc is the type for functions that can handle Query and return Result.Returns non-nil [error] if Query cannot be handled.
type QueryRegistry ¶ added in v1.3.0
type QueryRegistry interface {
// OnQuery registers [QueryHandlerFunc] for [QueryType] value.
//
// Note: for composition root usage only, not for dynamic [QueryHandlerFunc] registration.
OnQuery(QueryType, QueryHandlerFunc)
}
QueryRegistry is the interface implemented by types that can register QueryHandlerFunc for QueryType value.