Documentation
¶
Overview ¶
Package event defines the domain-event contract and the in-process synchronous event bus shared by all platform services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func On ¶
func On[E DomainEvent](s Subscriber, h func(ctx context.Context, e E) error)
On registers a typed handler with the subscriber. The routing key is taken from the event type itself, so the call site carries no string and the wiring is compiler-checked: a handler for E can only ever be registered under E's own name. Go does not allow generic methods, so this is a free function over the Subscriber rather than a method on it.
event.On(sub, assetHandler.HandleAssetCreated) // E inferred as *asset.Created
E's Name must be safe to call on its zero value — it must return a constant and never dereference the receiver — because On reads the routing key from a zero E at registration time (no reflection). A type that violates this fails fast at registration with a clear error rather than a cryptic nil panic.
Types ¶
type DomainEvent ¶
type DomainEvent interface {
Name() string
}
DomainEvent is the contract every aggregate-raised event implements.
type Handler ¶
type Handler func(ctx context.Context, e DomainEvent) error
Handler reacts to a single domain event.
type Publisher ¶
type Publisher interface {
Publish(ctx context.Context, e DomainEvent) error
PublishAll(ctx context.Context, events []DomainEvent) error
}
Publisher dispatches domain events to the in-process sync event bus.
type Subscriber ¶
Subscriber registers domain event handlers on the in-process sync event bus.
type TypedHandler ¶
type TypedHandler[E DomainEvent] func(ctx context.Context, e E) error
TypedHandler reacts to a single concrete domain-event type E. It is the typed counterpart of Handler, which receives the erased DomainEvent interface.