sticky

package
v0.0.0-...-57d6a8b Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

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.

func (FileDB) Append

func (db FileDB) Append(bs []byte) error

Append adds data to the file with a newline.

func (FileDB) Reader

func (db FileDB) Reader() (io.ReadCloser, error)

Reader opens the file and returns its reader.

type JSONDuration

type JSONDuration time.Duration

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

type JSONTime time.Time

JSONTime is a time type that can be converted to json.

func (JSONTime) MarshalJSON

func (t JSONTime) MarshalJSON() ([]byte, error)

MarshalJSON converts the value to json.

func (*JSONTime) UnmarshalJSON

func (t *JSONTime) UnmarshalJSON(bs []byte) error

UnmarshalJSON converts the time from json.

type MemoryDB

type MemoryDB struct {
	Content string
}

MemoryDB stores Events in memory.

Usefull for testing.

func NewMemoryDB

func NewMemoryDB(content string) *MemoryDB

NewMemoryDB initializes a MemoryDB

func (*MemoryDB) Append

func (db *MemoryDB) Append(bs []byte) error

Append adds a new event.

func (*MemoryDB) Reader

func (db *MemoryDB) Reader() (io.ReadCloser, error)

Reader reads the content.

type Option

type Option[Model any] func(s *Sticky[Model])

Option is a option for sticky.New()

func WithNow

func WithNow[Model any](now func() time.Time) Option[Model]

WithNow uses a special now function. Default is time.Now()

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]) Read

func (s *Sticky[Model]) Read(f func(Model))

Read calls a function that has access to an instance of the model for reading.

func (*Sticky[Model]) Write

func (s *Sticky[Model]) Write(f func(Model) Event[Model]) error

Write calls a function that has access to an instance of the model for writing. It has to return an event.

Write can return a ValidationError or ExecutionError when the event can not be processed.

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

func (err ValidationError) Unwrap() error

Jump to

Keyboard shortcuts

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