eventing

package module
v0.0.0-...-1cf6fb1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 6 Imported by: 0

README

eventing

Documentation

Index

Constants

View Source
const (
	EndOfStream = 0
)

Version constants

View Source
const (
	NoVersion = 0
)

NoVersion constants

Variables

View Source
var (
	ErrNotCommandHandler = errors.New("AggregateNotHandler")
)

Errors

Functions

func SortRecords

func SortRecords(r []Record)

SortRecords sorts records using their version

Types

type Aggregate

type Aggregate interface {
	On(Event) error
}

Aggregate interface

type AggregateFactory

type AggregateFactory func() Aggregate

AggregateFactory creates a brand new aggregate when called

type Command

type Command interface {
	AggregateID() string
}

Command represents a change request

type CommandHandler

type CommandHandler interface {
	Apply(context.Context, Command) ([]Event, error)
}

CommandHandler is anything that can take in a command a return events based on it

type CommandModel

type CommandModel struct {
	ID string
}

CommandModel implements the Command interface

func (CommandModel) AggregateID

func (c CommandModel) AggregateID() string

AggregateID implements the Command interface

type Event

type Event interface {
	AggregateID() string
	EventVersion() int
	EventAt() time.Time
}

Event interface

type EventModel

type EventModel struct {
	ID      string
	Version int
	At      time.Time
}

EventModel implements the Event interface

func (EventModel) AggregateID

func (e EventModel) AggregateID() string

AggregateID implements the Event interface

func (EventModel) EventAt

func (e EventModel) EventAt() time.Time

EventAt implements the Event interface

func (EventModel) EventVersion

func (e EventModel) EventVersion() int

EventVersion implements the Event interface

type EventNamer

type EventNamer interface {
	EventName() string
}

EventNamer is an event that can name itself

type JSONSerializer

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

JSONSerializer implements the Serializer interface

func NewJSONSerializer

func NewJSONSerializer(events ...Event) *JSONSerializer

NewJSONSerializer serializes events into/out of JSON, it uses reflection to get the new events and so events should not have any behaviour depending on some initialization like a custom constructor

func (*JSONSerializer) Deserialize

func (s *JSONSerializer) Deserialize(record Record) (Event, error)

Deserialize implements the Serializer interface

func (*JSONSerializer) Serialize

func (s *JSONSerializer) Serialize(event Event) (Record, error)

Serialize implements the Serializer interface

type Record

type Record struct {
	Data    []byte
	Version int
}

Record is an event that was serialzied

type Repository

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

Repository interface

func New

func New(factory AggregateFactory, options ...RepositoryOption) *Repository

New creates a new repository with the given aggregate and options

func (*Repository) Dispatch

func (r *Repository) Dispatch(ctx context.Context, cmd Command) (version int, err error)

Dispatch is a helper function that applies a command to an aggregate and saves the events. The aggregate must implement the CommandHandler interface

func (*Repository) Load

func (r *Repository) Load(ctx context.Context, aggregateID string) (Aggregate, error)

Load loads up an aggregate from events

func (*Repository) Save

func (r *Repository) Save(ctx context.Context, aggregateID string, events []Event) error

Save the events from an aggregate

type RepositoryOption

type RepositoryOption func(*Repository)

RepositoryOption applies a different option onto the repository

func WithSerializer

func WithSerializer(s Serializer) RepositoryOption

WithSerializer adds a custom serializer to the repository

func WithStore

func WithStore(s Store) RepositoryOption

WithStore adds a custom store to the repository

type Serializer

type Serializer interface {
	Serialize(event Event) (Record, error)
	Deserialize(record Record) (Event, error)
}

Serializer serializes/deserializes an event

type Store

type Store interface {
	Load(context.Context, string, int, int) ([]Record, error)
	Save(context.Context, string, []Record) error
}

Store represents an event store for serialized events this is used for supporting different backends

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

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