Introduction
go-eventsource is a package for building an Event Store
The package is under development and the interfaces may change.
Event Sourcing Basics
How to use it
To create a new repository:
NewRepository(store, serializer)
It has an interface for saving events and loading an aggregate.
type Repository interface {
Save(ctx context.Context, events ...Event) error
SaveTransaction(ctx context.Context, events ...Event) (StoreTransaction, error)
Load(ctx context.Context, id string, aggr Aggregate) (deleted bool, err error)
}
The package comes with one serializer and two stores:
Included serializer:
Included stores:
If you want to add your own store or serializer, the package has these defined interfaces.
type Store interface {
NewTransaction(ctx context.Context, records ...Record) (StoreTransaction, error)
Load(ctx context.Context, id string) (record []Record, err error)
}
type StoreTransaction interface {
Commit() error
Rollback() error
}
type Serializer interface {
Unmarshal(data []byte, eventType string) (Event, error)
Marshal(event Event) ([]byte, error)
}