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 CommandHandler
- type CommandHandlerFunc
- type CommandRegistry
- type CommandType
- type Event
- type EventHandler
- type EventHandlerFunc
- type EventRegistry
- type EventStreamer
- type EventType
- type Projection
- type ProjectionBuilder
- type Query
- 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 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(CommandType, CommandHandlerFunc) // OnCommand registers [CommandHandlerFunc] for [CommandType] value.
}
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 EventHandler ¶
type EventHandler interface {
HandleEvent(context.Context, Event) error // HandleEvent implements [EventHandlerFunc].
}
EventHandler is the interface implemented by types that can handle Event.
type EventHandlerFunc ¶
EventHandlerFunc is the type for functions that can handle Event Returns non-nil [error] if Event cannot be handled.
type EventRegistry ¶ added in v1.3.0
type EventRegistry interface {
OnEvent(EventType, EventHandlerFunc) // OnEvent registers [EventHandlerFunc] for [EventType] value.
}
EventRegistry is the interface implemented by types that can register EventHandlerFunc for EventType value.
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 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(QueryType, QueryHandlerFunc) // OnQuery registers [QueryHandlerFunc] for [QueryType] value.
}
QueryRegistry is the interface implemented by types that can register QueryHandlerFunc for QueryType value.