Documentation
¶
Index ¶
Constants ¶
const ( AggregateNil = "AggregateNil" DuplicateID = "DuplicateID" DuplicateVersion = "DuplicateVersion" DuplicateAt = "DuplicateAt" DuplicateType = "DuplicateType" InvalidID = "InvalidID" InvalidAt = "InvalidAt" InvalidVersion = "InvalidVersion" InvalidEncoding = "InvalidEncoding" UnboundEventType = "UnboundEventType" AggregateNotFound = "AggregateNotFound" UnhandledEvent = "UnhandledEvent" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Aggregate ¶
type Aggregate interface {
// On will be called for each event processed; returns true if aggregate was able to handle the event, false otherwise
On(event Event) bool
}
Aggregate represents the aggregate root in the domain driven design sense. It aggregates the events and presents the current view of the domain object
type EpochMillis ¶
type EpochMillis int64
EpochMillis represents the number of millis since Jan 1, 1970
func Time ¶
func Time(t time.Time) EpochMillis
Time converts a time.Time to an EpochMillis ; units of time less than millis are lost
func (EpochMillis) Int64 ¶
func (e EpochMillis) Int64() int64
Int64 converts EpochMillis to int64 representation
func (EpochMillis) String ¶
func (e EpochMillis) String() string
String represents EpochMillis as a numeric string
func (EpochMillis) Time ¶
func (e EpochMillis) Time() time.Time
Time converts EpochMillis to an instance of time.Time
type Error ¶
type Error interface {
error
// Returns the original error if one was set. Nil is returned if not set.
Cause() error
// Returns the short phrase depicting the classification of the error.
Code() string
// Returns the error details message.
Message() string
}
Error provides a standardized error interface for eventsource
type Event ¶
type Event interface {
// AggregateID returns the aggregate id of the event
AggregateID() string
// Version contains version number of aggregate
EventVersion() int
// At indicates when the event took place
EventAt() time.Time
}
Event describes a change that happened to the aggregate.
* Past tense, EmailChanged * Contains intent, EmailChanged is better than EmailSet
type EventTyper ¶
type EventTyper interface {
// EventType returns the name of event type
EventType() string
}
EventTyper is an optional interface that can be applied to an Event that allows it to specify an event type different than the name of the struct
type History ¶
type History []Record
History represents the events to be applied to recreate the aggregate in version order
type Model ¶
type Model struct {
// ID contains the AggregateID
ID string
// Version holds the event version
Version int
// At contains the event time
At time.Time
}
Model provides a default implementation of an Event that is suitable for being embedded
func (Model) AggregateID ¶
AggregateID implements part of the Event interface
func (Model) EventVersion ¶
EventVersion implements part of the Event interface
type Option ¶
type Option func(registry *repository)
func WithSerializer ¶
func WithSerializer(serializer Serializer) Option
type Record ¶
type Record struct {
// Version is the event version the Data represents
Version int
// At indicates when the event happened; provided as a utility for the store
At EpochMillis
// Data contains the Serializer encoded version of the data
Data []byte
}
Record provides the shape of the records to be saved to the db
type Repository ¶
type Repository interface {
Bind(events ...Event) error
Load(ctx context.Context, aggregateID string) (Aggregate, error)
Save(ctx context.Context, events ...Event) error
New() Aggregate
}
func New ¶
func New(prototype Aggregate, opts ...Option) Repository
type Serializer ¶
type Serializer interface {
Bind(events ...Event) error
Serialize(event Event) (Record, error)
Deserialize(record Record) (Event, error)
}
func JSONSerializer ¶
func JSONSerializer() Serializer
type Store ¶
type Store interface {
// Save saves events to the store
Save(ctx context.Context, aggregateID string, records ...Record) error
// Fetch retrieves the History of events with the specified aggregate id
Fetch(ctx context.Context, aggregateID string, version int) (History, error)
}
Store provides storage for events