es

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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() string
	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 string,
	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() string

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

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

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 string)

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

type EntityID

type EntityID = string

type Metadata

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

func NewMetadata

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

func (*Metadata) Datetime

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

func (*Metadata) EntityID

func (m *Metadata) EntityID() string

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