Documentation ¶
Index ¶
- Constants
- func DeleteAggregate(name string, id uuid.UUID) command.Cmd[DeleteAggregatePayload]
- func Handle(ctx context.Context, bus command.Bus, repo aggregate.Repository, ...) (<-chan error, error)
- func MustHandle(ctx context.Context, bus command.Bus, repo aggregate.Repository, ...) <-chan error
- func RegisterCommands(r codec.Registerer)
- func RegisterEvents(r codec.Registerer)
- type AggregateDeletedData
- type DeleteAggregatePayload
- type HandleOption
Constants ¶
const AggregateDeleted = "goes.command.aggregate.deleted"
AggregateDeleted is published when an aggregate has been deleted.
const DeleteAggregateCmd = "goes.command.aggregate.delete"
DeleteAggregateCmd is the name of the DeleteAggregate command.
Variables ¶
This section is empty.
Functions ¶
func DeleteAggregate ¶
DeleteAggregate returns the command to delete an aggregate. When using the built-in command handler of this package, aggregates are deleted by deleting their events from the event store. Additionally, a "goes.command.aggregate.deleted" is published after deletion.
This command completely deletes the event stream of the aggregate. Consider using soft-deletes instead.
func Handle ¶
func Handle(ctx context.Context, bus command.Bus, repo aggregate.Repository, opts ...HandleOption) (<-chan error, error)
Handle registers command handlers for the built-in commands and returns a channel of asynchronous command errors, or a single error if it fails to register the commands. When ctx is canceled, command handling stops and the returned error channel is closed.
The following commands are handled:
- DeleteAggregateCmd ("goes.command.aggregate.delete")
func MustHandle ¶
func MustHandle(ctx context.Context, bus command.Bus, repo aggregate.Repository, opts ...HandleOption) <-chan error
MustHandle does the same as Handle, but panic if command registration fails.
func RegisterCommands ¶
func RegisterCommands(r codec.Registerer)
RegisterCommands registers the built-in commands into a command registry.
func RegisterEvents ¶
func RegisterEvents(r codec.Registerer)
RegisterEvents registers events of built-in commands into an event registry.
Types ¶
type AggregateDeletedData ¶
type AggregateDeletedData struct { // Version is the version of the deleted aggregate. // // The aggregateVersion() returned by an AggregateDeleted event always // returns 0. Use this Version to see which version the aggregate has before // it was deleted. Version int }
AggregateDeletedData is the event data for the aggregateDeleted event.
type DeleteAggregatePayload ¶
type DeleteAggregatePayload struct{}
DeleteAggregatePayload is the command payload for deleting an aggregate.
type HandleOption ¶
type HandleOption func(*handleConfig)
HandleOption is an option for Handle & MustHandle.
func DeleteEvent ¶ added in v0.1.2
DeleteEvent returns a HandleOption that overrides the deletion event for the given aggregate. By default, when the PublishEvents() option is used, a "goes.command.aggregate.deleted" event is published when an aggregate is deleted from the event store. This option calls the provided makeEvent function with a reference to the deleted aggregate to override the published event. An empty aggregate name is a wildcard for all aggregates to allow for overriding the deletion event for all aggregates.
func PublishEvents ¶
func PublishEvents(bus event.Bus, store event.Store) HandleOption
PublishEvents returns a HandleOption that configures the command handler to publish events over the provided Bus when appropriate. If the optional store is non-nil, the events are also inserted into store after publishing.
The following events are published by the handler:
- aggregateDeleted ("goes.command.aggregate.deleted") (or a user-provided event, see DeleteEvent())