Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when trying to fetch a Snapshot that doesn't // exist. ErrNotFound = errors.New("snapshot not found") )
var ErrUnimplemented = errors.New("aggregate does not implement (Un)Marshaler, encoding.Binary(Un)Marshaler or encoding.Text(Un)Marshaler")
ErrUnimplemented is returned when trying to marshal or unmarshal a snapshot into an aggregate that does not implement one of the supported marshalers.
Functions ¶
func Marshal ¶
Marshal encodes the given aggregate into a byte slice. If a implements Marshaler, a.MarshalSnapshot() is returned. If a implements encoding.BinaryMarshaler, a.MarshalBinary() is returned and if a implements encoding.TextMarshaler, a.MarshalText is returned. If a implements none of these interfaces, Marshal uses encoding/gob to marshal the snapshot.
func Test ¶ added in v0.1.2
Test tests the Snapshot s against the Query q and returns true if q should include s in its results. Test can be used by Store implementations to filter events based on the query.
func Unmarshal ¶
Unmarshal decodes the given snapshot into the given aggregate. If a implements Unmarshaler, a.UnmarshalSnapshot() is returned. If a implements encoding.BinaryMarshaler, a.UnmarshalBinary() is returned and if a implements encoding.TextUnmarshaler, a.UnmarshalText() is returned. If a implements none of these interfaces, encoding/gob is used to unmarshal the snapshot.
Types ¶
type Marshaler ¶
A Marshaler can encode itself into bytes. aggregates must implement Marshaler & Unmarshaler for Snapshots to work.
Example using encoding/gob:
type foo struct { aggregate.Aggregate state } type state struct { Name string Age uint8 } func (f *foo) MarshalSnapshot() ([]byte, error) { var buf bytes.Buffer err := gob.NewEncoder(&buf).Encode(f.state) return buf.Bytes(), err } func (f *foo) UnmarshalSnapshot(p []byte) error { return gob.NewDecoder(bytes.NewReader(p)).Decode(&f.state) }
type Option ¶
type Option func(*snapshot)
Option is an option for creating a snapshot.
type Query ¶
type Query interface { aggregate.Query Times() time.Constraints }
Query is a query for snapshots.
type Schedule ¶
type Schedule interface { // Test returns true if the given aggregate should be snapshotted. Test(aggregate.Aggregate) bool }
A Schedule determines if an aggregate is scheduled to be snapshotted.
type Snapshot ¶
type Snapshot interface { // AggregateName returns the name of the aggregate. AggregateName() string // AggregateID returns the UUID of the aggregate. AggregateID() uuid.UUID // AggregateVersion returns the version of the aggregate at the time of the snapshot. AggregateVersion() int // Time returns the time of the snapshot. Time() time.Time // State returns the encoded state of the aggregate at the time of the snapshot. State() []byte }
Snapshot is a snapshot of an aggregate.
type Store ¶
type Store interface { // Save saves the given Snapshot into the Store. Save(context.Context, Snapshot) error // Latest returns the latest Snapshot for the aggregate with the given name // and UUID. Latest(context.Context, string, uuid.UUID) (Snapshot, error) // Version returns the Snapshot with the given version for the aggregate // with the given name and UUID. Implementations should return an error if // the specified Snapshot does not exist in the Store. Version(context.Context, string, uuid.UUID, int) (Snapshot, error) // Limit returns the latest Snapshot that has a version equal to or lower // than the given version. Implementations should return an error if no // such Snapshot can be found. Limit(context.Context, string, uuid.UUID, int) (Snapshot, error) // Query queries the Store for Snapshots that fit the given Query and // returns a channel of Snapshots and a channel of errors. // // Example: // // var store Store // snaps, errs, err := store.Query(context.TODO(), query.New()) // // handle err // err := streams.Walk(context.TODO(), func(snap Snapshot) { // log.Println(fmt.Sprintf("Queried Snapshot: %v", snap)) // foo := newFoo(snap.AggregateID()) // err := Unmarshal(snap, foo) // // handle err // }, snaps, errs) // // handle err Query(context.Context, Query) (<-chan Snapshot, <-chan error, error) // Delete deletes a Snapshot from the Store. Delete(context.Context, Snapshot) error }
Store is a database for aggregate snapshots.
type Target ¶
type Target interface {
SetVersion(int)
}
Target is a snapshot target. This should be an aggregate that implements the SetVersion function.
type Unmarshaler ¶
An Unmarshaler can decode itself from bytes.