event

package
v0.0.0-...-a320c80 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

MatchedSerializers represents all currently available serializers.

Functions

This section is empty.

Types

type Aggregator

type Aggregator interface {
	// GetID gets aggregate root id.
	GetId() string
	// SetID sets aggregate root id.
	SetId(id string)
	// GetType gets aggregate root type.
	GetType() string
	// SetType sets aggregate root type.
	SetType(typ string)
	// GetVerion gets current aggregate root version.
	GetVersion() Version
	// SetVersions sets current aggregate root version.
	SetVersion(version Version)
	// ListCommittedEvents returns list of all committed events.
	ListCommittedEvents() []Eventer
	// ListUncommittedEvents returns list of all uncommitted yet events.
	ListUncommittedEvents() []Eventer
	// Apply applies not committed yet event into aggregate root. Sets event
	// id, type and version same as current aggregate root state.
	Apply(event Eventer) error
	// ApplyCommitted applies already committed event into aggregate root. Sets
	// aggregate root id, type and version the same as current applied event.
	ApplyCommitted(event Eventer) error
	// Commit marks provided event as committed and removes
	// from uncommitted events list.
	Commit(event Eventer) error
}

Aggregator is main interface that responsibles for event aggregation. Aggregate is a cluster of associated objects treated as a single unit.

type BSONSerializer

type BSONSerializer struct{}

func (BSONSerializer) Decode

func (BSONSerializer) Decode(data Payload, dst interface{}) error

func (BSONSerializer) Encode

func (BSONSerializer) Encode(v interface{}) (Payload, error)

type Event

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

func MustNew

func MustNew(reason string, payload interface{}) *Event

func New

func New(reason string, payload interface{}) (*Event, error)

func NewWithSerializer

func NewWithSerializer(reason string, payload interface{}, serializerType SerializerType) (*Event, error)

func (*Event) GetAggregateId

func (evt *Event) GetAggregateId() string

func (*Event) GetAggregateType

func (evt *Event) GetAggregateType() string

func (*Event) GetPayload

func (evt *Event) GetPayload() Payload

func (*Event) GetReason

func (evt *Event) GetReason() string

func (*Event) GetSerializer

func (evt *Event) GetSerializer() SerializerType

func (*Event) GetTimestamp

func (evt *Event) GetTimestamp() Timestamp

func (*Event) GetVersion

func (evt *Event) GetVersion() Version

func (*Event) SetAggregateId

func (evt *Event) SetAggregateId(aggId string)

func (*Event) SetAggregateType

func (evt *Event) SetAggregateType(aggType string)

func (*Event) SetPayload

func (evt *Event) SetPayload(payload Payload)

func (*Event) SetReason

func (evt *Event) SetReason(reason string)

func (*Event) SetSerializer

func (evt *Event) SetSerializer(typ SerializerType)

func (*Event) SetTimestamp

func (evt *Event) SetTimestamp(tstamp Timestamp)

func (*Event) SetVersion

func (evt *Event) SetVersion(version Version)

type Eventer

type Eventer interface {
	GetAggregateId() string
	SetAggregateId(id string)
	GetAggregateType() string
	SetAggregateType(typ string)
	GetReason() string
	SetReason(reason string)
	GetVersion() Version
	SetVersion(version Version)
	GetTimestamp() Timestamp
	SetTimestamp(tstamp Timestamp)
	GetPayload() Payload
	SetPayload(payload Payload)
	GetSerializer() SerializerType
	SetSerializer(s SerializerType)
}

Eventer is a main interface with all basic getters/setters that responsibles for event manipulation.

func Covarience

func Covarience(events []*Event) []Eventer

type JSONSerializer

type JSONSerializer struct{}

func (JSONSerializer) Decode

func (JSONSerializer) Decode(data Payload, dst interface{}) error

func (JSONSerializer) Encode

func (JSONSerializer) Encode(v interface{}) (Payload, error)

type Payload

type Payload []byte

Payload represents an event payload (sequence of bytes).

type Serializer

type Serializer interface {
	Encode(v interface{}) (Payload, error)
	Decode(data Payload, dst interface{}) error
}

type SerializerType

type SerializerType string
const (
	SerializerTypeJSON SerializerType = "json"
	SerializerTypeBSON SerializerType = "bson"
)

type Timestamp

type Timestamp time.Time

Timestamp represents an event timestamp when event was created.

func (*Timestamp) Scan

func (t *Timestamp) Scan(value interface{}) error

func (Timestamp) Value

func (t Timestamp) Value() (driver.Value, error)

type Transition

type Transition func(event Eventer) error

Transition is a type that makes transition on already known event reason.

type UnsupportedSerializer

type UnsupportedSerializer struct{}

func (UnsupportedSerializer) Decode

func (UnsupportedSerializer) Decode(data Payload, dst interface{}) error

func (UnsupportedSerializer) Encode

func (UnsupportedSerializer) Encode(v interface{}) (Payload, error)

type Version

type Version int

Version represents event version. Default version is DirtyVersion.

const (
	DirtyVersion Version = -1
	EmptyVersion Version = 0
	NextVersion  Version = 1
)

Jump to

Keyboard shortcuts

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