ostore

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

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 EventType

type EventType int
const (
	EventTypeNone EventType = iota
	EventTypeCreate
	EventTypeUpdate
	EventTypeDelete
)

func (EventType) String

func (e EventType) String() string

type IObjectStore

type IObjectStore interface {
	// Set properties by key
	Set(key string, value map[string]any)
	// Update properties by key
	Update(key string, value 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
}

func NewMemoryStore

func NewMemoryStore() IObjectStore

NewMemoryStore creates a new MemoryStore

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

func (*MemoryStore) Keys

func (m *MemoryStore) Keys() []string

Keys returns a list of keys

func (*MemoryStore) Set

func (m *MemoryStore) Set(key string, kwargs map[string]any)

Create an object in the store by id and properties

func (*MemoryStore) Update

func (m *MemoryStore) Update(id string, kwargs map[string]any)

Update an object in the store by id and partial properties

type StoreEvent

type StoreEvent struct {
	// The type of event
	Type EventType
	// The id of the object
	Id string
	// The properties of the object
	Value 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)

Jump to

Keyboard shortcuts

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