event

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataOf

func DataOf[T any](e IEvent) T

func From

func From(event IEvent) *entry

Types

type AggID

type AggID = string

type Aggregate

type Aggregate interface {
	ID() string
	Type() string
	Version() int
}

type Event

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

func (Event) Aggregate

func (e Event) Aggregate() (id, name string, version int)

func (Event) Data

func (e Event) Data() interface{}

func (Event) ID

func (e Event) ID() ID

func (Event) MarshalBSON

func (e Event) MarshalBSON() ([]byte, error)

func (Event) Name

func (e Event) Name() string

func (Event) Time

func (e Event) Time() time.Time

func (*Event) UnmarshalBSON

func (e *Event) UnmarshalBSON(data []byte) error

type ID

type ID = string

type IEvent

type IEvent interface {
	// ID returns the id of the event.
	ID() ID
	// Name returns the name of the event.
	Name() string
	// Time returns the time of the event.
	Time() time.Time
	// Data returns the event data.
	Data() interface{}
	// Aggregate returns the id, name and version of the aggregate that the
	// event belongs to. aggregate should return zero values if the event is not
	// an aggregate event.
	Aggregate() (id string, name string, version int)
}

func For

func For[Data any](a Aggregate, name string, data Data, opts ...Option) IEvent

func New

func New(name string, data any, opts ...Option) IEvent

type Metadata

type Metadata struct {
	ID               ID
	Name             string
	Time             time.Time
	AggregateName    string
	AggregateID      AggID
	AggregateVersion int
	Data             interface{}
}

type Option

type Option func(*Metadata)

func WithAggregate

func WithAggregate(a Aggregate) Option

func WithID

func WithID(id ID) Option

func WithTime

func WithTime(t time.Time) Option

Jump to

Keyboard shortcuts

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