Documentation ¶
Index ¶
- type Event
- type FileDB
- type JSONDuration
- type JSONTime
- type MemoryDB
- type Option
- type Sticky
- func (s *Sticky[Model]) ForReading() (Model, func())
- func (s *Sticky[Model]) ForWriting() (Model, func(...Event[Model]) error, func())
- func (s *Sticky[Model]) Listen(ctx context.Context) func(yield func(val []string) bool)
- func (s *Sticky[Model]) Read(f func(Model) error) error
- func (s *Sticky[Model]) Write(f func(Model) Event[Model]) error
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event[Model any] interface { Validate(Model) error Execute(Model, time.Time) Model Name() string }
Event is a set of functions that can modify a model.
type FileDB ¶
type FileDB struct {
File string
}
FileDB is a evet database based of one file.
type JSONDuration ¶
JSONDuration is a duration type with a consum marshaling to json.
func (JSONDuration) MarshalJSON ¶
func (d JSONDuration) MarshalJSON() ([]byte, error)
MarshalJSON converts the value to json.
func (*JSONDuration) UnmarshalJSON ¶
func (d *JSONDuration) UnmarshalJSON(bs []byte) error
UnmarshalJSON converts the time from json.
type JSONTime ¶
JSONTime is a time type that can be converted to json.
func (JSONTime) MarshalJSON ¶
MarshalJSON converts the value to json.
func (*JSONTime) UnmarshalJSON ¶
UnmarshalJSON converts the time from json.
type MemoryDB ¶
type MemoryDB struct {
Content string
}
MemoryDB stores Events in memory.
Usefull for testing.
type Sticky ¶
type Sticky[Model any] struct { // contains filtered or unexported fields }
Sticky is some sort of db that persists a model on disk in a event storage way.
func New ¶
func New[Model any](db database, emptyModel Model, getEvent func(name string) Event[Model], os ...Option[Model]) (*Sticky[Model], error)
New initializes a new Sticky instance.
func (*Sticky[Model]) ForReading ¶
func (s *Sticky[Model]) ForReading() (Model, func())
ForReading returns the model for reading.
Call the done function, when reading is finished.
m, done := model.ForReading() defer done()
m...
func (*Sticky[Model]) ForWriting ¶
ForWriting returns the model for writing.
Call the write function with one or more events.
Call the done function, when you are done.
m, write, done := model.ForWriting() defer done()
event := ... write(event)
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
ValidationError happens, when the event can not be validated.
func (ValidationError) Error ¶
func (err ValidationError) Error() string
func (ValidationError) String ¶
func (err ValidationError) String() string
func (ValidationError) Unwrap ¶
func (err ValidationError) Unwrap() error