es

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 2 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[ID]
	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

This section is empty.

Types

type AggregateBase

type AggregateBase[ID EntityID, Snapshot Versioned] struct {
	// contains filtered or unexported fields
}

func NewAgg

func NewAgg[ID EntityID, Snapshot Versioned](
	id ID,
	entityType string,
	events []Event[ID, 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 EntityID

type EntityID interface {
	Empty() bool
	Eq(id EntityID) bool
	String() string
}

type Event

type Event[ID EntityID, Snapshot any] interface {
	EntityType() string
	EntityID() ID
	Type() string
	Version() int
	Datetime() time.Time
	Apply(*Snapshot) error
}

type Metadata

type Metadata[ID EntityID] struct {
	// contains filtered or unexported fields
}

func NewMetadata

func NewMetadata[ID EntityID](
	entityType string,
	entityID ID,
	type_ string,
	version int) Metadata[ID]

func (Metadata[ID]) Datetime

func (b Metadata[ID]) Datetime() time.Time

func (Metadata[ID]) EntityID

func (b Metadata[ID]) EntityID() ID

func (Metadata[ID]) EntityType

func (b Metadata[ID]) EntityType() string

func (Metadata[ID]) Type

func (b Metadata[ID]) Type() string

func (Metadata[ID]) Version

func (b Metadata[ID]) Version() int

type SnapshotWithVersion

type SnapshotWithVersion interface {
	SetVersion(int)
}

type Versioned

type Versioned interface {
	SetVersion(int)
}

Jump to

Keyboard shortcuts

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