Documentation ¶
Index ¶
- Variables
- func GetType(e Event) reflect.Type
- func GetTypeName(e Event) string
- func NewULID() string
- type Aggregate
- type AggregatorMock
- type BaseEvent
- type Event
- type NotificationService
- type NotificationServiceMock
- type Record
- type Repository
- type RepositoryMock
- func (r RepositoryMock) GetEventsBySequenceID(ctx context.Context, sequenceID string, limit int) ([]Event, error)
- func (r RepositoryMock) GetEventsBySequenceIDAndType(ctx context.Context, sequenceID string, eventType Event, limit int) ([]Event, error)
- func (r RepositoryMock) GetEventsByTimestamp(ctx context.Context, timestamp int64, limit int) ([]Event, error)
- func (r RepositoryMock) Load(ctx context.Context, id string, aggr Aggregate) (deleted bool, err error)
- func (r RepositoryMock) Save(ctx context.Context, events ...Event) error
- func (r RepositoryMock) SaveTransaction(ctx context.Context, events ...Event) (StoreTransaction, error)
- func (r RepositoryMock) SetNotificationService(ns NotificationService)
- type Serializer
- type SerializerMock
- type Store
- type StoreMock
- func (o StoreMock) LoadByAggregate(ctx context.Context, aggregateID string) (record []Record, err error)
- func (o StoreMock) LoadBySequenceID(ctx context.Context, sequenceID string, limit int) (record []Record, err error)
- func (o StoreMock) LoadBySequenceIDAndType(ctx context.Context, sequenceID string, eventType string, limit int) (record []Record, err error)
- func (o StoreMock) LoadByTimestamp(ctx context.Context, timestamp int64, limit int) (record []Record, err error)
- func (o StoreMock) NewTransaction(ctx context.Context, records ...Record) (StoreTransaction, error)
- type StoreTransaction
- type StoreTransactionMock
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDeleted is returned by Aggregate.On() method to signal that the object has been deleted ErrDeleted = errors.New("not found (was deleted)") // ErrNoHistory is returned by Repository.Load() when no history exist for the given aggregate ID ErrNoHistory = errors.New("no history found") )
Functions ¶
func GetType ¶ added in v1.3.2
GetType the type of the given input value, or if input is a pointer, return the type of the pointed to object
func GetTypeName ¶ added in v1.3.2
GetTypeName the type of the given input value, or if input is a pointer, return the type of the pointed to object
Types ¶
type Aggregate ¶
Aggregate is an interface representing an object whose state changes can be recorded to and replayed from an event source.
type AggregatorMock ¶
AggregatorMock is a mock
func CreateAggregatorMock ¶
func CreateAggregatorMock() *AggregatorMock
CreateAggregatorMock returns a aggregatorMock
func (AggregatorMock) On ¶
func (o AggregatorMock) On(ctx context.Context, event Event) error
On is a mock
func (AggregatorMock) SetAggregateID ¶
func (o AggregatorMock) SetAggregateID(id string)
SetAggregateID is not implemented
type BaseEvent ¶
type BaseEvent struct { AggregateID string `json:"aggregateId"` UserID string `json:"userId"` SequenceID string `json:"sequenceId"` Timestamp int64 `json:"timestamp"` }
BaseEvent ...
func (BaseEvent) GetSequenceID ¶ added in v1.3.0
GetSequenceID ...
func (BaseEvent) GetTimestamp ¶ added in v1.3.0
GetTimestamp ...
func (*BaseEvent) SetSequenceID ¶ added in v1.3.0
SetSequenceID ...
func (*BaseEvent) SetTimestamp ¶ added in v1.3.0
SetTimestamp ...
type Event ¶
type Event interface { GetAggregateID() string GetUserID() string GetSequenceID() string GetTimestamp() int64 SetSequenceID(string) SetTimestamp(int64) }
Event ...
type NotificationService ¶ added in v1.4.0
NotificationService represents a service which can emit notifications when records are saved to the event source
type NotificationServiceMock ¶ added in v1.4.0
func CreateNotificationServiceMock ¶ added in v1.4.0
func CreateNotificationServiceMock() *NotificationServiceMock
CreateNotificationServiceMock creates a notification service mock
func (NotificationServiceMock) SendNotification ¶ added in v1.4.0
func (ns NotificationServiceMock) SendNotification(record Record) error
type Record ¶
type Record struct { AggregateID string `json:"aggregateId"` SequenceID string `json:"sequenceId"` Timestamp int64 `json:"timestamp"` Type string `json:"type"` Data []byte `json:"data"` UserID string `json:"userId"` }
Record is a store row. The Data field contains the marshalled Event, and Type is the type of event retrieved by reflect.TypeOf(event).
type Repository ¶
type Repository interface { // Save one or more events to the repository Save(ctx context.Context, events ...Event) error // Save one or more events to the repository, within a transaction SaveTransaction(ctx context.Context, events ...Event) (StoreTransaction, error) // Load events from repository for the given aggregate ID. For each event e, // call aggr.On(e) to update the state of aggr. When done, aggr has been // "fast forwarded" to the current state. Load(ctx context.Context, id string, aggr Aggregate) (deleted bool, err error) // Get all events with sequence ID newer than the given ID (see https://github.com/oklog/ulid) // Return at most limit records. If limit is 0, don't limit the number of records returned. GetEventsBySequenceID(ctx context.Context, sequenceID string, limit int) (events []Event, err error) // Same as GetEventsBySequenceID, but only returns events of the same type // as the one provided in the eventType parameter. GetEventsBySequenceIDAndType(ctx context.Context, sequenceID string, eventType Event, limit int) (events []Event, err error) // Get all events newer than the given timestamp // Return at most limit records. If limit is 0, don't limit the number of records returned. GetEventsByTimestamp(ctx context.Context, timestamp int64, limit int) (events []Event, err error) // Set notification service SetNotificationService(notificationService NotificationService) }
Repository is an interface representing the actual event source.
func NewRepository ¶
func NewRepository(store Store, serializer Serializer) Repository
NewRepository returns a new repository
type RepositoryMock ¶
RepositoryMock is a mock
func CreateRepositoryMock ¶
func CreateRepositoryMock() *RepositoryMock
CreateRepositoryMock returns a repositoryMock
func (RepositoryMock) GetEventsBySequenceID ¶ added in v1.3.0
func (r RepositoryMock) GetEventsBySequenceID(ctx context.Context, sequenceID string, limit int) ([]Event, error)
GetEventsBySequenceID is a mock
func (RepositoryMock) GetEventsBySequenceIDAndType ¶ added in v1.3.2
func (r RepositoryMock) GetEventsBySequenceIDAndType(ctx context.Context, sequenceID string, eventType Event, limit int) ([]Event, error)
GetEventsBySequenceIDAndType is a mock
func (RepositoryMock) GetEventsByTimestamp ¶ added in v1.3.0
func (r RepositoryMock) GetEventsByTimestamp(ctx context.Context, timestamp int64, limit int) ([]Event, error)
GetEventsByTimestamp is a mock
func (RepositoryMock) Load ¶
func (r RepositoryMock) Load(ctx context.Context, id string, aggr Aggregate) (deleted bool, err error)
Load is a mock
func (RepositoryMock) Save ¶
func (r RepositoryMock) Save(ctx context.Context, events ...Event) error
Save is a mock
func (RepositoryMock) SaveTransaction ¶ added in v1.2.0
func (r RepositoryMock) SaveTransaction(ctx context.Context, events ...Event) (StoreTransaction, error)
SaveTransaction is a mock
func (RepositoryMock) SetNotificationService ¶ added in v1.4.0
func (r RepositoryMock) SetNotificationService(ns NotificationService)
SetNotificationService is a mock
type Serializer ¶
type Serializer interface { Unmarshal(data []byte, eventType string) (event Event, err error) Marshal(event Event) (data []byte, err error) }
Serializer is an interface that should be implemented if events need to be saved using a new storage format.
type SerializerMock ¶
SerializerMock is a mock
func CreateSerializerMock ¶
func CreateSerializerMock() *SerializerMock
CreateSerializerMock returns a serializerMock
type Store ¶
type Store interface { NewTransaction(ctx context.Context, records ...Record) (StoreTransaction, error) LoadByAggregate(ctx context.Context, aggregateID string) (record []Record, err error) LoadBySequenceID(ctx context.Context, sequenceID string, limit int) (record []Record, err error) LoadBySequenceIDAndType(ctx context.Context, sequenceID string, eventType string, limit int) (records []Record, err error) LoadByTimestamp(ctx context.Context, timestamp int64, limit int) (record []Record, err error) }
Store is the interface implemented by the data stores that can be used as back end for the event source.
type StoreMock ¶
StoreMock is a mock
func (StoreMock) LoadByAggregate ¶ added in v1.3.0
func (o StoreMock) LoadByAggregate(ctx context.Context, aggregateID string) (record []Record, err error)
LoadByAggregate is a mock
func (StoreMock) LoadBySequenceID ¶ added in v1.3.0
func (o StoreMock) LoadBySequenceID(ctx context.Context, sequenceID string, limit int) (record []Record, err error)
LoadBySequenceID is a mock
func (StoreMock) LoadBySequenceIDAndType ¶ added in v1.3.2
func (o StoreMock) LoadBySequenceIDAndType(ctx context.Context, sequenceID string, eventType string, limit int) (record []Record, err error)
LoadBySequenceIDAndType is a mock
func (StoreMock) LoadByTimestamp ¶ added in v1.3.0
func (o StoreMock) LoadByTimestamp(ctx context.Context, timestamp int64, limit int) (record []Record, err error)
LoadByTimestamp is a mock
func (StoreMock) NewTransaction ¶ added in v1.2.0
NewTransaction is a mock
type StoreTransaction ¶ added in v1.2.0
StoreTransaction encapsulates a write operation to a Store, allowing the caller to roll back the operation.
type StoreTransactionMock ¶ added in v1.2.0
StoreTransactionMock is a mock
func CreateStoreTransactionMock ¶ added in v1.2.0
func CreateStoreTransactionMock() *StoreTransactionMock
CreateStoreTransactionMock returns a store transaction mock
func (StoreTransactionMock) Commit ¶ added in v1.2.0
func (o StoreTransactionMock) Commit() error
Commit is a mock
func (StoreTransactionMock) Rollback ¶ added in v1.2.0
func (o StoreTransactionMock) Rollback() error
Rollback is a mock