goddd

package module
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const REMOVED_EVENT_NAME = "removed"

Variables

View Source
var ConcurrencyError = errors.New("concurrency error while saving")
View Source
var InvalidUpdateCallback = errors.New("callback should return a non nil object if error is nil")

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 MigrateMongoDB added in v1.4.0

func MigrateMongoDB(mongoDB *mongo.Database, dir string) 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 Deserialize added in v1.3.5

func Deserialize(message []byte) (Event, error)

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) Serialize added in v1.3.5

func (event Event) Serialize() ([]byte, error)

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) OnEvent added in v1.3.5

func (p *EventPublisher) OnEvent(event Event)

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)
}

func NewRemoteEventPublisher added in v1.3.5

func NewRemoteEventPublisher(queue services.QueueService, errChan chan<- error) EventReceiver

type EventStream

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

EventStream is an interface representing a stream of events

type InMemoryRepository

type InMemoryRepository[T DomainObject] struct {
	// contains filtered or unexported fields
}

func NewInMemoryRepository

func NewInMemoryRepository[T DomainObject](publisher *EventPublisher) InMemoryRepository[T]

func (*InMemoryRepository[T]) EventsSince added in v1.2.0

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

func (*InMemoryRepository[T]) Exists

func (r *InMemoryRepository[T]) Exists(ctx context.Context, objectId string) (bool, error)

func (*InMemoryRepository[T]) Load

func (r *InMemoryRepository[T]) Load(ctx context.Context, objectID string, object T) error

func (*InMemoryRepository[T]) Remove added in v1.5.0

func (r *InMemoryRepository[T]) Remove(ctx context.Context, objectID string, object T) error

func (*InMemoryRepository[T]) Save

func (r *InMemoryRepository[T]) Save(ctx context.Context, object T) error

func (*InMemoryRepository[T]) Update added in v1.4.0

func (r *InMemoryRepository[T]) Update(ctx context.Context, objectID string, object T, nbRetries int, updater func(T) (T, error)) (T, error)

type MongoRepository

type MongoRepository[T DomainObject] struct {
	// contains filtered or unexported fields
}

func NewMongoRepository

func NewMongoRepository[T DomainObject](database *mongo.Database, publisher *EventPublisher) (*MongoRepository[T], error)

func (*MongoRepository[T]) EventsSince added in v1.2.0

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

func (*MongoRepository[T]) Exists

func (r *MongoRepository[T]) Exists(ctx context.Context, objectId string) (bool, error)

func (*MongoRepository[T]) Load

func (r *MongoRepository[T]) Load(ctx context.Context, objectID string, object T) error

func (*MongoRepository[T]) ObjectEventsSinceVersion added in v1.3.1

func (r *MongoRepository[T]) ObjectEventsSinceVersion(ctx context.Context, objectID string, version int) ([]Event, error)

func (*MongoRepository[T]) Remove added in v1.5.0

func (r *MongoRepository[T]) Remove(ctx context.Context, objectID string, object T) error

func (*MongoRepository[T]) Save

func (r *MongoRepository[T]) Save(ctx context.Context, object T) error

func (*MongoRepository[T]) Update added in v1.4.0

func (r *MongoRepository[T]) Update(ctx context.Context, objectID string, object T, nbRetries int, updater func(T) (T, error)) (T, error)

type RemoteEventListener added in v1.3.5

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

func NewRemoteEventListener added in v1.3.5

func NewRemoteEventListener(queue services.QueueService, receiver EventReceiver, errChan chan<- error) RemoteEventListener

func (*RemoteEventListener) Listen added in v1.3.5

func (r *RemoteEventListener) Listen()

type RemoteEventPublisher added in v1.3.5

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

func (*RemoteEventPublisher) OnEvent added in v1.3.5

func (r *RemoteEventPublisher) OnEvent(event Event)

type Repository

type Repository[T DomainObject] interface {
	Save(ctx context.Context, object T) error
	Load(ctx context.Context, objectID string, object T) error
	Exists(ctx context.Context, objectID string) (bool, error)
	EventsSince(ctx context.Context, time time.Time, limit int) ([]Event, error)
	Update(ctx context.Context, objectID string, object T, nbRetries int, updater func(T) (T, error)) (T, error)
	Remove(ctx context.Context, objectID string, object T) 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) CollectUnsavedEvents added in v1.3.9

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

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
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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