ev

package
v0.0.0-...-74cc791 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregate

type Aggregate interface {
	BaseAggregate
	Root() *AggregateRoot
	Transition(e Event)
}

All aggregate must implement this interface

type AggregateRoot

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

func (*AggregateRoot) AggregateID

func (ar *AggregateRoot) AggregateID() string

func (*AggregateRoot) AggregateType

func (ar *AggregateRoot) AggregateType() string

func (*AggregateRoot) ApplyChange

func (ar *AggregateRoot) ApplyChange(agg Aggregate, data interface{})

ApplyChange apply data change on aggregate

func (*AggregateRoot) ApplyChangeWithMetadata

func (ar *AggregateRoot) ApplyChangeWithMetadata(agg Aggregate, data interface{}, metadata map[string]interface{})

func (*AggregateRoot) BaseVersion

func (ar *AggregateRoot) BaseVersion() int

BaseVersion is the version of current aggregate in database

func (*AggregateRoot) CloneEvents

func (ar *AggregateRoot) CloneEvents() []Event

CloneEvents return new slice of events

func (*AggregateRoot) Events

func (ar *AggregateRoot) Events() []Event

func (*AggregateRoot) IsUnsaved

func (ar *AggregateRoot) IsUnsaved() bool

func (*AggregateRoot) LoadFromHistory

func (ar *AggregateRoot) LoadFromHistory(agg Aggregate, events []Event)

LoadFromHistory build aggregate from list event

func (*AggregateRoot) Root

func (ar *AggregateRoot) Root() *AggregateRoot

func (*AggregateRoot) SetAggregateType

func (ar *AggregateRoot) SetAggregateType(typ string)

func (*AggregateRoot) SetID

func (ar *AggregateRoot) SetID(id string) error

func (*AggregateRoot) SetInternal

func (ar *AggregateRoot) SetInternal(id string, baseVersion, version int)

setInternal set common data to AggregateRoot

func (*AggregateRoot) Update

func (ar *AggregateRoot) Update()

update update version

func (*AggregateRoot) Version

func (ar *AggregateRoot) Version() int

Version is the version of aggregate not stored

type BaseAggregate

type BaseAggregate interface {
	RegisterEvents(RegisterEventsFunc) error
}

type Event

type Event struct {
	ID          int64       `json:"id"`
	AggregateID string      `json:"aggregate_id"`
	Version     int         `json:"version"`
	EventType   string      `json:"event_type"`
	Data        interface{} `json:"data"`
	Metadata    dtype.JSON  `json:"metadata"`

	CreatedAt time.Time `json:"created_at"`
}

type RegisterEventsFunc

type RegisterEventsFunc = func(events ...interface{}) error

type Serializer

type Serializer interface {
	ToEventsFunc(events ...interface{}) []eventFunc
	RegisterAggregate(agg BaseAggregate) error
	Register(agg Aggregate, eventsFunc []eventFunc) error
	RegisterTypes(agg Aggregate, eventsFunc ...eventFunc) error
	Type(typ, name string) (eventFunc, bool)
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
}

func NewSerializer

func NewSerializer() Serializer

Jump to

Keyboard shortcuts

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