Documentation
¶
Overview ¶
Package es implements a common support for Event Sourcing.
To use, you should extend your Entity Aggregate from the AggregateBase struct.
Example:
package loans
import (
"fmt"
"github.com/AltScore/gothic/pkg/es"
)
const EntityType = "loans"
type Aggregate struct {
es.AggregateBase[ID, Snapshot]
}
Your events should extend the Event struct:
type flowStarted struct {
es.Metadata[ID]
ClientID ClientID
TransactionID string
TotalAmount Money
}
Package samples contains sample code for using gothic.
Index ¶
- type AggregateBase
- func (a *AggregateBase[ID, Snapshot]) Apply(e Event[ID, Snapshot]) error
- func (a *AggregateBase[ID, Snapshot]) EntityType() string
- func (a *AggregateBase[ID, Snapshot]) GetNewEvents() []Event[ID, Snapshot]
- func (a *AggregateBase[ID, Snapshot]) ID() ID
- func (a *AggregateBase[ID, Snapshot]) NewMetadata(eventType string) Metadata[ID]
- func (a *AggregateBase[ID, Snapshot]) Raise(e Event[ID, Snapshot]) error
- func (a *AggregateBase[ID, Snapshot]) Replay() error
- func (a *AggregateBase[ID, Snapshot]) SetId(id ID)
- func (a *AggregateBase[ID, Snapshot]) Snapshot() *Snapshot
- func (a *AggregateBase[ID, Snapshot]) Version() int
- type EntityID
- type Event
- type Metadata
- type VersionUpdater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregateBase ¶
func NewAgg ¶
func NewAgg[ID EntityID, Snapshot any]( id ID, entityType string, events []Event[ID, Snapshot], updater VersionUpdater[Snapshot], ) AggregateBase[ID, Snapshot]
func (*AggregateBase[ID, Snapshot]) Apply ¶
func (a *AggregateBase[ID, Snapshot]) Apply(e Event[ID, Snapshot]) error
Apply process an already existent event to update the current Snapshot En error is returned in case the event is incorrect for this Snapshot
func (*AggregateBase[ID, Snapshot]) EntityType ¶
func (a *AggregateBase[ID, Snapshot]) EntityType() string
func (*AggregateBase[ID, Snapshot]) GetNewEvents ¶
func (a *AggregateBase[ID, Snapshot]) GetNewEvents() []Event[ID, Snapshot]
func (*AggregateBase[ID, Snapshot]) ID ¶ added in v0.1.4
func (a *AggregateBase[ID, Snapshot]) ID() ID
func (*AggregateBase[ID, Snapshot]) NewMetadata ¶
func (a *AggregateBase[ID, Snapshot]) NewMetadata(eventType string) Metadata[ID]
func (*AggregateBase[ID, Snapshot]) Raise ¶
func (a *AggregateBase[ID, Snapshot]) Raise(e Event[ID, Snapshot]) error
Raise process a new event to update the current Snapshot and append it to the past events
func (*AggregateBase[ID, Snapshot]) Replay ¶
func (a *AggregateBase[ID, Snapshot]) Replay() error
func (*AggregateBase[ID, Snapshot]) SetId ¶
func (a *AggregateBase[ID, Snapshot]) SetId(id ID)
func (*AggregateBase[ID, Snapshot]) Snapshot ¶
func (a *AggregateBase[ID, Snapshot]) Snapshot() *Snapshot
func (*AggregateBase[ID, Snapshot]) Version ¶
func (a *AggregateBase[ID, Snapshot]) Version() int
type Metadata ¶
type Metadata[ID EntityID] struct { // contains filtered or unexported fields }
func NewMetadata ¶
func (Metadata[ID]) EntityType ¶
type VersionUpdater ¶ added in v0.1.6
VersionUpdater is a function that can be implemented by the Snapshot to set the version
Click to show internal directories.
Click to hide internal directories.