es

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 4 Imported by: 1

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
	ClientID      ClientID
	TransactionID string
	TotalAmount   Money
}

Package samples contains sample code for using gothic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reify added in v0.2.2

func Reify[Agg Aggregate[SS], SS Snapshot](previousEvents []event.Event, factory func(AggregateBase[SS]) Agg, opts ...Option[SS]) (Agg, error)

Reify recreates an aggregate from a list of events stored to its current state.

Types

type Aggregate added in v0.2.2

type Aggregate[SS Snapshot] interface {
	ID() ids.ID
	Type() string
	Version() int
	Snapshot() SS
	Apply(e event.Event) error
	Replay() error
}

type AggregateBase

type AggregateBase[SS Snapshot] struct {
	// contains filtered or unexported fields
}

func NewAgg

func NewAgg[SS Snapshot](
	id ids.ID,
	type_ string,
	events []event.Event,
	opts ...Option[SS],
) AggregateBase[SS]

func (*AggregateBase[SS]) Apply

func (a *AggregateBase[SS]) Apply(e event.Event) 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[SS]) GetNewEvents

func (a *AggregateBase[SS]) GetNewEvents() []event.Event

func (*AggregateBase[SS]) HasEventsToSave added in v0.2.0

func (a *AggregateBase[SS]) HasEventsToSave() bool

func (*AggregateBase[SS]) ID added in v0.1.4

func (a *AggregateBase[SS]) ID() ids.ID

func (*AggregateBase[SS]) NewMetadata

func (a *AggregateBase[SS]) NewMetadata(eventType string) Metadata

func (*AggregateBase[SS]) Raise

func (a *AggregateBase[SS]) Raise(e event.Event) error

Raise process a new event to update the current Snapshot and append it to the past events

func (*AggregateBase[SS]) Replay

func (a *AggregateBase[SS]) Replay() error

func (*AggregateBase[SS]) SetId

func (a *AggregateBase[SS]) SetId(id ids.ID)

func (*AggregateBase[SS]) Snapshot

func (a *AggregateBase[SS]) Snapshot() SS

func (*AggregateBase[SS]) Type added in v0.2.0

func (a *AggregateBase[SS]) Type() string

func (*AggregateBase[SS]) Version

func (a *AggregateBase[SS]) Version() int

func (*AggregateBase[SS]) WithEventsSaved added in v0.7.1

func (a *AggregateBase[SS]) WithEventsSaved() AggregateBase[SS]

type EntityID

type EntityID = string

type Metadata

type Metadata struct {
	// contains filtered or unexported fields
}

func NewMetadata

func NewMetadata(
	entityType string,
	entityID ids.ID,
	type_ string,
	version int) Metadata

func (*Metadata) Datetime

func (m *Metadata) Datetime() time.Time

func (*Metadata) EntityID

func (m *Metadata) EntityID() ids.ID

func (*Metadata) EntityType

func (m *Metadata) EntityType() string

func (*Metadata) Type

func (m *Metadata) Type() string

func (*Metadata) Version

func (m *Metadata) Version() int

type Option added in v0.2.0

type Option[SS Snapshot] func(*AggregateBase[SS])

func WithSnapshot added in v0.2.0

func WithSnapshot[SS Snapshot](snapshot SS) Option[SS]

type Snapshot added in v0.2.0

type Snapshot interface {
	Apply(event.Event) error
	SetVersion(int)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL