Documentation ¶
Index ¶
- func Dispatch(aggregate AggregateHandler, event Event)
- func GenerateUUID() string
- func GetTypeName(source interface{}) (reflect.Type, string)
- func NewFailure(err error, typ FailureType, command Command) error
- func ReduceHelper(aggregate AggregateHandler, event Event, commit bool)
- type AggregateHandler
- type BaseAggregate
- func (b *BaseAggregate) AddError(err error)
- func (b *BaseAggregate) AddEvent(event Event)
- func (b *BaseAggregate) AttachCommandID(id string)
- func (b *BaseAggregate) ClearUncommited()
- func (b *BaseAggregate) GetError() error
- func (b *BaseAggregate) GetID() string
- func (b *BaseAggregate) GetVersion() int
- func (b *BaseAggregate) HasError() bool
- func (b *BaseAggregate) IncrementVersion()
- func (b *BaseAggregate) Uncommited() []Event
- type BaseCommand
- type Command
- type CommandBus
- type CommandHandler
- type CommandHandlerRegister
- type CommandRegister
- type Event
- type EventBus
- type EventStore
- type EventType
- type EventTypeRegister
- type Failure
- type FailureType
- type Register
- type Repository
- func (r *Repository) Load(aggregate AggregateHandler, id string) error
- func (r *Repository) PublishError(err error, command Command, bucket, subset string) error
- func (r *Repository) PublishEvents(aggregate AggregateHandler, bucket, subset string) error
- func (r *Repository) SafeSave(aggregate AggregateHandler, version int) error
- func (r *Repository) Save(aggregate AggregateHandler, version int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
func Dispatch(aggregate AggregateHandler, event Event)
Dispatch process the event and commit it
func GetTypeName ¶
GetTypeName of given struct
func NewFailure ¶
func NewFailure(err error, typ FailureType, command Command) error
NewFailure returns an alert that implements an error interface
func ReduceHelper ¶
func ReduceHelper(aggregate AggregateHandler, event Event, commit bool)
ReduceHelper increments the version of an aggregate and apply the change itself
Types ¶
type AggregateHandler ¶
type AggregateHandler interface { // LoadsFromHistory(events []Event) Reduce(event Event) error HandleCommand(Command) error AddEvent(Event) AttachCommandID(id string) Uncommited() []Event ClearUncommited() IncrementVersion() GetID() string GetVersion() int AddError(error) GetError() error HasError() bool }
AggregateHandler defines the methods to process commands
type BaseAggregate ¶
BaseAggregate contains the basic info that all aggregates should have
func (*BaseAggregate) AddError ¶
func (b *BaseAggregate) AddError(err error)
AddError to the aggregate
func (*BaseAggregate) AddEvent ¶
func (b *BaseAggregate) AddEvent(event Event)
AddEvent to the aggregate
func (*BaseAggregate) AttachCommandID ¶
func (b *BaseAggregate) AttachCommandID(id string)
AttachCommandID to every change for traceability
func (*BaseAggregate) ClearUncommited ¶
func (b *BaseAggregate) ClearUncommited()
ClearUncommited the events
func (*BaseAggregate) GetError ¶
func (b *BaseAggregate) GetError() error
GetError returns a list of errors
func (*BaseAggregate) GetVersion ¶
func (b *BaseAggregate) GetVersion() int
GetVersion of the current aggregate
func (*BaseAggregate) HasError ¶
func (b *BaseAggregate) HasError() bool
HasError returns true if it contains at least one error
func (*BaseAggregate) IncrementVersion ¶
func (b *BaseAggregate) IncrementVersion()
IncrementVersion ads 1 to the current version
func (*BaseAggregate) Uncommited ¶
func (b *BaseAggregate) Uncommited() []Event
Uncommited return the events to be saved
type BaseCommand ¶
type BaseCommand struct { ID string Type string AggregateID string AggregateType string Version int }
BaseCommand contains the basic info that all commands should have
func (*BaseCommand) GenerateUUID ¶
func (b *BaseCommand) GenerateUUID()
GenerateUUID generates an uuid
func (*BaseCommand) GetAggregateID ¶
func (b *BaseCommand) GetAggregateID() string
GetAggregateID returns the command aggregate ID
func (*BaseCommand) GetAggregateType ¶
func (b *BaseCommand) GetAggregateType() string
GetAggregateType returns the command aggregate type
func (*BaseCommand) GetType ¶
func (b *BaseCommand) GetType() string
GetType returns the command type
func (*BaseCommand) IsValid ¶
func (b *BaseCommand) IsValid() bool
IsValid checks validates the command
type Command ¶
type Command interface { GetType() string GetID() string GenerateUUID() GetAggregateID() string GetAggregateType() string IsValid() bool GetVersion() int }
Command contains the methods to retreive basic info about it
type CommandBus ¶
CommandBus serve as the bridge between commands and command handler it should manage the queues
type CommandHandler ¶
CommandHandler defines the contract to handle commands
type CommandHandlerRegister ¶
type CommandHandlerRegister interface { Add(command interface{}, handler CommandHandler) GetHandler(command interface{}) (CommandHandler, error) }
CommandHandlerRegister stores the handlers for commands
type CommandRegister ¶
type CommandRegister struct {
// contains filtered or unexported fields
}
CommandRegister contains a registry of command-handler style
func NewCommandRegister ¶
func NewCommandRegister() *CommandRegister
NewCommandRegister creates a new CommandHandler
func (*CommandRegister) Add ¶
func (c *CommandRegister) Add(command interface{}, handler CommandHandler)
Add a new command with its handler
func (*CommandRegister) GetHandler ¶
func (c *CommandRegister) GetHandler(command interface{}) (CommandHandler, error)
GetHandler the handler for a command
type Event ¶
type Event struct { ID string `json:"id"` AggregateID string `json:"aggregate_id"` AggregateType string `json:"aggregate_type"` CommandID string `json:"command_id"` Version int `json:"version"` Type string `json:"type"` Data interface{} `json:"data"` }
Event stores the data for every event
type EventStore ¶
type EventStore interface { Save(events []Event, version int) error SafeSave(events []Event, version int) error Load(aggregateID string) ([]Event, error) }
EventStore saves the events from an aggregate
type EventType ¶
type EventType struct {
// contains filtered or unexported fields
}
EventType implements the EventyTypeRegister interface
type EventTypeRegister ¶
EventTypeRegister defines the register for all the events that are Data field child of event struct
func NewEventRegister ¶
func NewEventRegister() EventTypeRegister
NewEventRegister gets a EventyTypeRegister interface
type Failure ¶
type Failure struct { CommandID string `json:"command_id"` CommandType string `json:"command_type"` CommandVersion int `json:"command_version"` AggregateID string `json:"aggregate_id"` AggregateType string `json:"aggregate_type"` Type FailureType `json:"type"` Err error `json:"error"` }
Failure is an error while the command is being processed
type FailureType ¶
type FailureType string
FailureType defines the alert(error) type while a command is being processed
const ( FailureLoadingEvents FailureType = "loading_events" FailureReplayingEvents FailureType = "replying_events" FailureProcessingCommand FailureType = "processing_command" FailureInvalidID FailureType = "invalid_id" FailureSavingOnStorage FailureType = "saving_on_storage" FailurePublishingEvents FailureType = "publishing_events" FailureVersionMissmatch FailureType = "version_missmatch" )
nolint
type Register ¶
type Register interface { Set(source interface{}) Get(name string) (interface{}, error) Count() int }
Register defines generic methods to create a registry
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository is responsible to generate an Aggregate save events and publish it
func NewRepository ¶
func NewRepository(store EventStore, bus EventBus) *Repository
NewRepository creates a repository wieh a eventstore and eventbus access
func (*Repository) Load ¶
func (r *Repository) Load(aggregate AggregateHandler, id string) error
Load restore the last state of an aggregate
func (*Repository) PublishError ¶
func (r *Repository) PublishError(err error, command Command, bucket, subset string) error
PublishError to an eventBus
func (*Repository) PublishEvents ¶
func (r *Repository) PublishEvents(aggregate AggregateHandler, bucket, subset string) error
PublishEvents to an eventBus
func (*Repository) SafeSave ¶
func (r *Repository) SafeSave(aggregate AggregateHandler, version int) error
SafeSave the events without check the version
func (*Repository) Save ¶
func (r *Repository) Save(aggregate AggregateHandler, version int) error
Save the events and publish it to eventbus