Documentation ¶
Overview ¶
Package ostore provides a simple object store for the simulation. A object-store is a key-value store for objects. The objects are identified by a unique key. The objects are maps of properties (kwargs) in form of `map[string]any`. The object store is used to store the state of the simulation for each object. A watcher can be registered to get notified on changes to the store.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrObjectNotFound is returned when an object is not found ErrObjectNotFound = errors.New("object not found") // ErrObjectExists is returned when an object already exists ErrObjectExists = errors.New("object already exists") // ErrPropertyNotFound is returned when a property is not found ErrPropertyNotFound = errors.New("property not found") )
Functions ¶
This section is empty.
Types ¶
type IObjectStore ¶
type IObjectStore interface { // Set properties by key Set(key string, kwargs map[string]any) // Update properties by key Update(key string, kwargs map[string]any) // Get properties by key Get(key string) map[string]any // Delete properties by key Delete(key string) // Has returns true if the store has the key Has(key string) bool // Keys returns a list of keys Keys() []string // OnEvent for changes to the store OnEvent(fn StoreNotifyFunc) StoreUnWatch }
type MemoryStore ¶
type MemoryStore struct { StoreWatcher // contains filtered or unexported fields }
MemoryStore is an in-memory implementation of IObjectStore
func (*MemoryStore) Delete ¶
func (m *MemoryStore) Delete(key string)
Delete an object in the store by id
func (*MemoryStore) Get ¶
func (m *MemoryStore) Get(key string) map[string]any
Get an object from the store by id
func (*MemoryStore) Has ¶
func (m *MemoryStore) Has(key string) bool
Has returns true if the object exists in the store
type StoreEvent ¶
type StoreEvent struct { // The type of event Type EventType // The id of the object Id string // The properties of the object KWArgs map[string]any }
func (StoreEvent) IsNone ¶
func (e StoreEvent) IsNone() bool
type StoreNotifyFunc ¶
type StoreNotifyFunc func(event StoreEvent)
type StoreUnWatch ¶
type StoreUnWatch func()
type StoreWatchObject ¶
type StoreWatchObject struct {
// contains filtered or unexported fields
}
type StoreWatcher ¶
type StoreWatcher struct {
// contains filtered or unexported fields
}
func (*StoreWatcher) OnEvent ¶
func (w *StoreWatcher) OnEvent(fn StoreNotifyFunc) StoreUnWatch
func (*StoreWatcher) UnWatch ¶
func (w *StoreWatcher) UnWatch(id string)
Click to show internal directories.
Click to hide internal directories.