goddd

package module
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode added in v1.2.0

func Decode(object interface{}, data []byte) error

func Encode added in v1.2.0

func Encode(object interface{}) ([]byte, error)

func NewIdentity

func NewIdentity(objectType string) string

Types

type DomainObject

type DomainObject interface {
	EventStream

	ObjectID() string
	Apply(eventName string, eventPayload []byte) error
}

DomainObject is an interface representing a domain object necessary methods

type DomainObjectMemento added in v1.3.0

type DomainObjectMemento interface {
	DumpMemento() (msgp.Marshaler, error)
	ApplyMemento(payload []byte) error
	SetVersion(version int)
}

DomainObjectMemento is an interface representing a domain object capable of exposing a memento

type Event

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

Event represents a domain Event

func NewEvent

func NewEvent(objectID string, eventName string, version int, payload []byte) Event

NewEvent create a new event from the given parameters

func ReloadEvent added in v1.2.1

func ReloadEvent(eventID, objectID, eventName string, version int, payload []byte, timestamp int64) Event

func (Event) Id

func (event Event) Id() string

Id of the domain event

func (Event) Name

func (event Event) Name() string

Name of the event

func (Event) ObjectId

func (event Event) ObjectId() string

ObjectId the event is linked to

func (Event) Payload

func (event Event) Payload() []byte

Payload of the event as byte array

func (Event) Timestamp

func (event Event) Timestamp() int64

Timestamp of the event

func (Event) Version

func (event Event) Version() int

Version of the domain event

type EventPublisher

type EventPublisher struct {
	Wait bool
	// contains filtered or unexported fields
}

func NewEventPublisher

func NewEventPublisher() EventPublisher

func (*EventPublisher) Publish

func (p *EventPublisher) Publish(events []Event)

func (*EventPublisher) Register

func (p *EventPublisher) Register(receiver EventReceiver)

type EventReceiver

type EventReceiver interface {
	OnEvent(event Event)
}

type EventStream

type EventStream interface {
	AddEvent(object DomainObject, eventName string, payload msgp.Marshaler) error
	LoadEvent(object DomainObject, event Event) error
	Events() []Event
	LastVersion() int
	SetStreamVersion(version int)
	ContainsEventWithId(eventID string) bool
	Clear()
}

EventStream is an interface representing a stream of events

type InMemoryRepository

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

func NewInMemoryRepository

func NewInMemoryRepository(publisher *EventPublisher) InMemoryRepository

func (*InMemoryRepository) EventsSince added in v1.2.0

func (r *InMemoryRepository) EventsSince(timestamp time.Time, limit int) ([]Event, error)

func (*InMemoryRepository) Exists

func (r *InMemoryRepository) Exists(objectId string) (bool, error)

func (*InMemoryRepository) Load

func (r *InMemoryRepository) Load(objectID string, object DomainObject) error

func (*InMemoryRepository) Save

func (r *InMemoryRepository) Save(object DomainObject) error

type MongoRepository

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

func NewMongoRepository

func NewMongoRepository(database *mongo.Database, publisher *EventPublisher) MongoRepository

func (*MongoRepository) EventsSince added in v1.2.0

func (r *MongoRepository) EventsSince(timestamp time.Time, limit int) ([]Event, error)

func (*MongoRepository) Exists

func (r *MongoRepository) Exists(objectId string) (bool, error)

func (*MongoRepository) Load

func (r *MongoRepository) Load(objectID string, object DomainObject) error

func (*MongoRepository) ObjectEventsSinceVersion added in v1.3.1

func (r *MongoRepository) ObjectEventsSinceVersion(objectID string, version int) ([]Event, error)

func (*MongoRepository) Save

func (r *MongoRepository) Save(object DomainObject) error

type Repository

type Repository interface {
	Save(object DomainObject) error
	Load(objectID string, object DomainObject) error
	Exists(objectID string) (bool, error)
	EventsSince(time time.Time, limit int) ([]Event, error)
}

type Stream

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

Stream is an implementation of an EventStream

func NewEventStream

func NewEventStream() Stream

NewEventStream initializes a new event stream

func (*Stream) AddEvent

func (s *Stream) AddEvent(object DomainObject, eventName string, payload msgp.Marshaler) error

AddEvent add a new event into the stream

func (*Stream) Clear added in v1.1.1

func (s *Stream) Clear()

Clear clears the stream

func (*Stream) ContainsEventWithId

func (s *Stream) ContainsEventWithId(eventId string) bool

ContainsEventWithId checks if an event is known in the stream

func (*Stream) Events

func (s *Stream) Events() []Event

Events returns all the events of this stream

func (*Stream) LastVersion

func (s *Stream) LastVersion() int

LastVersion returns the last known version

func (*Stream) LoadEvent

func (s *Stream) LoadEvent(object DomainObject, event Event) error

LoadEvent load an existing event into the stream

func (*Stream) SetStreamVersion added in v1.3.1

func (s *Stream) SetStreamVersion(version int)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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