Documentation
¶
Index ¶
- func RegisterEvent[K comparable, T EventPayload](eventStore *EventStore[K], event T)
- func RegisterSnapshot[K comparable, T SnapshotPayload](snapshotStore *SnapshotStore[K], snapshot T)
- type Aggregate
- type AggregateID
- type AggregateRoot
- type AggregateStore
- type ErrAggregateVersionConflict
- type ErrUnknownAggregateChangeType
- type ErrUnknownAggregateSnapshotType
- type ErrUnregisteredEvent
- type ErrUnregisteredSnapshot
- type Event
- type EventLoadHooks
- type EventPayload
- type EventRepository
- type EventSaveHooks
- type EventStore
- type EventsPostLoad
- type EventsPostSave
- type EventsPreLoad
- type EventsPreSave
- type Hook
- func EventsPostLoadHook[K comparable](fn EventsPostLoad[K]) Hook[K]
- func EventsPostSaveHook[K comparable](fn EventsPostSave[K]) Hook[K]
- func EventsPreLoadHook[K comparable](fn EventsPreLoad[K]) Hook[K]
- func EventsPreSaveHook[K comparable](fn EventsPreSave[K]) Hook[K]
- func SnapshotPostLoadHook[K comparable](fn SnapshotPostLoad[K]) Hook[K]
- func SnapshotPostSaveHook[K comparable](fn SnapshotPostSave[K]) Hook[K]
- func SnapshotPreLoadHook[K comparable](fn SnapshotPreLoad[K]) Hook[K]
- func SnapshotPreSaveHook[K comparable](fn SnapshotPreSave[K]) Hook[K]
- type Hooks
- func (h Hooks[K]) EventsPostLoad(ctx context.Context, aggregate AggregateRoot[K], events []Event[K]) error
- func (h Hooks[K]) EventsPostSave(ctx context.Context, aggregate AggregateRoot[K], events []Event[K]) error
- func (h Hooks[K]) EventsPreLoad(ctx context.Context, aggregate AggregateRoot[K]) error
- func (h Hooks[K]) EventsPreSave(ctx context.Context, aggregate AggregateRoot[K], events []Event[K]) error
- func (h Hooks[K]) SnapshotPostLoad(ctx context.Context, aggregate AggregateRoot[K], snapshot *Snapshot[K]) error
- func (h Hooks[K]) SnapshotPostSave(ctx context.Context, aggregate AggregateRoot[K], snapshot Snapshot[K]) error
- func (h Hooks[K]) SnapshotPreLoad(ctx context.Context, aggregate AggregateRoot[K]) error
- func (h Hooks[K]) SnapshotPreSave(ctx context.Context, aggregate AggregateRoot[K], snapshot Snapshot[K]) error
- type Snapshot
- type SnapshotAggregate
- type SnapshotLoadHooks
- type SnapshotPayload
- type SnapshotPostLoad
- type SnapshotPostSave
- type SnapshotPreLoad
- type SnapshotPreSave
- type SnapshotRepository
- type SnapshotSaveHooks
- type SnapshotStore
- func (s *SnapshotStore[K]) Load(ctx context.Context, aggregate AggregateRoot[K], hooks ...Hook[K]) error
- func (s *SnapshotStore[K]) Save(ctx context.Context, aggregate AggregateRoot[K], hooks ...Hook[K]) error
- func (s *SnapshotStore[K]) WithEventStore(eventStore *EventStore[K]) *SnapshotStore[K]
- func (s *SnapshotStore[K]) WithRepository(repository SnapshotRepository[K]) *SnapshotStore[K]
- type SnapshotStrategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterEvent ¶ added in v0.2.0
func RegisterEvent[K comparable, T EventPayload](eventStore *EventStore[K], event T)
func RegisterSnapshot ¶ added in v0.2.0
func RegisterSnapshot[K comparable, T SnapshotPayload](snapshotStore *SnapshotStore[K], snapshot T)
Types ¶
type Aggregate ¶
type Aggregate[K comparable] interface { AggregateID() K AggregateVersion() int TrackChange(aggregate AggregateRoot[K], event EventPayload) error TrackChanges(aggregate AggregateRoot[K], events ...EventPayload) error Changes() []EventPayload SetID(K) SetVersion(int) // contains filtered or unexported methods }
func NewAggregate ¶
func NewAggregate[K comparable](id AggregateID[K]) Aggregate[K]
type AggregateID ¶
type AggregateID[K comparable] interface { Get() K // Get the current ID; this can return a zero value and IsSet should be used to check for zero values New() K // Generate new ID based on type-specific rules Set(K) // Set the ID if it is not already set IsSet() bool // Check against type-specific zero value rules }
type AggregateRoot ¶
type AggregateRoot[K comparable] interface { Aggregate[K] AggregateType() string ApplyChange(event EventPayload) error }
type AggregateStore ¶
type AggregateStore[K comparable] interface { Load(ctx context.Context, aggregate AggregateRoot[K], hooks ...Hook[K]) error Save(ctx context.Context, aggregate AggregateRoot[K], hooks ...Hook[K]) error }
type ErrAggregateVersionConflict ¶
type ErrAggregateVersionConflict struct { AggregateID any AggregateType string AggregateVersion int }
func (ErrAggregateVersionConflict) Error ¶
func (e ErrAggregateVersionConflict) Error() string
type ErrUnknownAggregateChangeType ¶
type ErrUnknownAggregateChangeType struct { AggregateType string Change EventPayload }
func (ErrUnknownAggregateChangeType) Error ¶
func (e ErrUnknownAggregateChangeType) Error() string
type ErrUnknownAggregateSnapshotType ¶
type ErrUnknownAggregateSnapshotType struct { AggregateType string Snapshot SnapshotPayload }
func (ErrUnknownAggregateSnapshotType) Error ¶
func (e ErrUnknownAggregateSnapshotType) Error() string
type ErrUnregisteredEvent ¶ added in v0.2.0
type ErrUnregisteredEvent string
func (ErrUnregisteredEvent) Error ¶ added in v0.2.0
func (e ErrUnregisteredEvent) Error() string
type ErrUnregisteredSnapshot ¶ added in v0.2.0
type ErrUnregisteredSnapshot string
func (ErrUnregisteredSnapshot) Error ¶ added in v0.2.0
func (e ErrUnregisteredSnapshot) Error() string
type EventLoadHooks ¶
type EventPayload ¶ added in v0.2.0
type EventPayload interface {
Kind() string
}
type EventRepository ¶
type EventSaveHooks ¶
type EventStore ¶ added in v0.2.0
type EventStore[K comparable] struct { // contains filtered or unexported fields }
func NewEventStore ¶
func NewEventStore[K comparable]( repository EventRepository[K], hooks ...Hook[K], ) *EventStore[K]
func (*EventStore[K]) WithRepository ¶ added in v0.2.1
func (s *EventStore[K]) WithRepository(repository EventRepository[K]) *EventStore[K]
WithRepository returns a new EventStore with the provided repository.
type EventsPostLoad ¶
type EventsPostLoad[K comparable] func(ctx context.Context, aggregate AggregateRoot[K], events []Event[K]) error
type EventsPostSave ¶
type EventsPostSave[K comparable] func(ctx context.Context, aggregate AggregateRoot[K], events []Event[K]) error
type EventsPreLoad ¶
type EventsPreLoad[K comparable] func(ctx context.Context, aggregate AggregateRoot[K]) error
type EventsPreSave ¶
type EventsPreSave[K comparable] func(ctx context.Context, aggregate AggregateRoot[K], events []Event[K]) error
type Hook ¶
type Hook[K comparable] interface { EventSaveHooks[K] EventLoadHooks[K] SnapshotSaveHooks[K] SnapshotLoadHooks[K] }
func EventsPostLoadHook ¶
func EventsPostLoadHook[K comparable](fn EventsPostLoad[K]) Hook[K]
func EventsPostSaveHook ¶
func EventsPostSaveHook[K comparable](fn EventsPostSave[K]) Hook[K]
func EventsPreLoadHook ¶
func EventsPreLoadHook[K comparable](fn EventsPreLoad[K]) Hook[K]
func EventsPreSaveHook ¶
func EventsPreSaveHook[K comparable](fn EventsPreSave[K]) Hook[K]
func SnapshotPostLoadHook ¶
func SnapshotPostLoadHook[K comparable](fn SnapshotPostLoad[K]) Hook[K]
func SnapshotPostSaveHook ¶
func SnapshotPostSaveHook[K comparable](fn SnapshotPostSave[K]) Hook[K]
func SnapshotPreLoadHook ¶
func SnapshotPreLoadHook[K comparable](fn SnapshotPreLoad[K]) Hook[K]
func SnapshotPreSaveHook ¶
func SnapshotPreSaveHook[K comparable](fn SnapshotPreSave[K]) Hook[K]
type Hooks ¶
type Hooks[K comparable] []Hook[K]
func (Hooks[K]) EventsPostLoad ¶
func (Hooks[K]) EventsPostSave ¶
func (Hooks[K]) EventsPreLoad ¶
func (Hooks[K]) EventsPreSave ¶
func (Hooks[K]) SnapshotPostLoad ¶
func (Hooks[K]) SnapshotPostSave ¶
func (Hooks[K]) SnapshotPreLoad ¶
type SnapshotAggregate ¶
type SnapshotAggregate[K comparable] interface { CreateSnapshot() SnapshotPayload ApplySnapshot(snapshot SnapshotPayload) error Aggregate[K] }
type SnapshotLoadHooks ¶
type SnapshotPayload ¶ added in v0.2.0
type SnapshotPayload interface {
Kind() string
}
type SnapshotPostLoad ¶
type SnapshotPostLoad[K comparable] func(ctx context.Context, aggregate AggregateRoot[K], snapshot *Snapshot[K]) error
type SnapshotPostSave ¶
type SnapshotPostSave[K comparable] func(ctx context.Context, aggregate AggregateRoot[K], snapshot Snapshot[K]) error
type SnapshotPreLoad ¶
type SnapshotPreLoad[K comparable] func(ctx context.Context, aggregate AggregateRoot[K]) error
type SnapshotPreSave ¶
type SnapshotPreSave[K comparable] func(ctx context.Context, aggregate AggregateRoot[K], snapshot Snapshot[K]) error
type SnapshotRepository ¶
type SnapshotSaveHooks ¶
type SnapshotStore ¶ added in v0.2.0
type SnapshotStore[K comparable] struct { // contains filtered or unexported fields }
func NewSnapshotStore ¶
func NewSnapshotStore[K comparable]( eventStore *EventStore[K], repository SnapshotRepository[K], strategy SnapshotStrategy[K], hooks ...Hook[K], ) *SnapshotStore[K]
func (*SnapshotStore[K]) WithEventStore ¶ added in v0.2.1
func (s *SnapshotStore[K]) WithEventStore(eventStore *EventStore[K]) *SnapshotStore[K]
WithEventStore returns a new SnapshotStore with the provided EventStore.
func (*SnapshotStore[K]) WithRepository ¶ added in v0.2.1
func (s *SnapshotStore[K]) WithRepository(repository SnapshotRepository[K]) *SnapshotStore[K]
WithRepository returns a new SnapshotStore with the provided SnapshotRepository.
type SnapshotStrategy ¶
type SnapshotStrategy[K comparable] interface { ShouldSnapshot(aggregate AggregateRoot[K]) bool }
func NewFrequencySnapshotStrategy ¶
func NewFrequencySnapshotStrategy[K comparable](frequency int) SnapshotStrategy[K]
NewFrequencySnapshotStrategy creates a new SnapshotStrategy that takes in a frequency value.
This strategy is useful when you want to snapshot the aggregate every N changes.
func NewParticularChangesSnapshotStrategy ¶
func NewParticularChangesSnapshotStrategy[K comparable](changes []any) SnapshotStrategy[K]
NewParticularChangesSnapshotStrategy creates a new SnapshotStrategy that takes in a list of changes.
This strategy is useful when you want to snapshot the aggregate when a particular change is applied.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.