Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteItem ¶
type ByteItem struct {
Value []byte
}
Simple raw item encoding - copies value bytes as is
type GobItem ¶
type GobItem struct {
Value interface{}
}
Gob encoding - serializes arbitrary value to/from gob format
type Item ¶
type Item interface { io.ReaderFrom io.WriterTo }
Item is something that can be put into a Store. Items should be able to read their values from io.Reader and write them into io.Writer. Several helper implemenations are provided - for raw bytes, for JSON and for gob format.
type JSONItem ¶
type JSONItem struct {
Value interface{}
}
JSON encoding - serializes arbitrary value to/from JSON
type Store ¶
type Store interface { Get(key string, item Item) Item Set(key string, item Item) <-chan error List(prefix string) []string Flush() <-chan error }
Store is the interface that wraps basic get/set functions for a simple key-value storage.
Store can be implemented as on-disk persistent storage, or as in-memory cache.
Get fulfils the item with the value associated with the key and returns the item. Caller must provide the item instance beforehand, because the way how item serializes/deserializes itself depends on its type. Get returns no errors explicitly, but nil is returned if key is missing or any other I/O error happended. Get is synchronous, your goroutine is blocked until item is fully read from the store.
Set writes item contents to the store at the given key. It's an asynchronous operation, but caller can read from the returned channel to wait for write completion and to get notified if I/O error occurred. If item is nil the key is removed from the store
List returns list of keys that exists and in the store and start with the given prefix. If prefix is an empty string - all keys are returned. List function is syncrhonous.
Flush waits for all writing goroutines to finish and syncs all store data to the disk. Flush can be called asynchronously, or the caller can wait for the actual flush to happen by reading from the returned channel.