store/main.go
2022-02-18 09:51:56 -08:00

44 lines
1.0 KiB
Go

package store
import "github.com/vmihailenco/msgpack/v5"
// Store represents a key value store
type Store interface {
// Set sets a key to a value
Set(key string, val interface{}) error
// Get places a value at a key into val
Get(key string, val interface{}) error
Delete(key string) error
// Bucket returns a bucket with the specified name
Bucket(name string) Bucket
// Iter returns an iterator
Iter() Iter
}
// Bucket represents a bucket within a store
type Bucket interface {
// Name returns the bucket name
Name() string
// Set sets a key in the bucket to a value
Set(string, interface{}) error
// Get places a value at a key in the bucket into val
Get(string, interface{}) error
Delete(key string) error
// Iter returns an iterator for the bucket
Iter() Iter
}
// Item represents an iterator item
type Item struct {
Key string
Data []byte
}
// Value sets out to the value of the item data
func (it *Item) Value(out interface{}) error {
return msgpack.Unmarshal(it.Data, out)
}
// Iter represents an iterator channel
type Iter <-chan *Item