Documentation
¶
Index ¶
- Constants
- Variables
- func Key(key ...string) string
- func ParseKey(key string) ([]string, error)
- type DataStore
- type KV
- type MockData
- type MockStore
- func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) (bool, error)
- func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, ...) (bool, *store.KVPair, error)
- func (s *MockStore) Close()
- func (s *MockStore) Delete(key string) error
- func (s *MockStore) DeleteTree(prefix string) error
- func (s *MockStore) Exists(key string) (bool, error)
- func (s *MockStore) Get(key string) (*store.KVPair, error)
- func (s *MockStore) List(prefix string) ([]*store.KVPair, error)
- func (s *MockStore) NewLock(key string, options *store.LockOptions) (store.Locker, error)
- func (s *MockStore) Put(key string, value []byte, options *store.WriteOptions) error
- func (s *MockStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error)
- func (s *MockStore) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error)
Constants ¶
const ( // NetworkKeyPrefix is the prefix for network key in the kv store NetworkKeyPrefix = "network" // EndpointKeyPrefix is the prefix for endpoint key in the kv store EndpointKeyPrefix = "endpoint" )
Variables ¶
var ( ErrKeyModified = store.ErrKeyModified ErrKeyNotFound = store.ErrKeyNotFound )
ErrKeyModified is raised for an atomic update when the update is working on a stale state
var ( // ErrNotImplmented exported ErrNotImplmented = errors.New("Functionality not implemented") )
Functions ¶
Types ¶
type DataStore ¶
type DataStore interface {
// GetObject gets data from datastore and unmarshals to the specified object
GetObject(key string, o KV) error
// PutObject adds a new Record based on an object into the datastore
PutObject(kvObject KV) error
// PutObjectAtomic provides an atomic add and update operation for a Record
PutObjectAtomic(kvObject KV) error
// DeleteObject deletes a record
DeleteObject(kvObject KV) error
// DeleteObjectAtomic performs an atomic delete operation
DeleteObjectAtomic(kvObject KV) error
// DeleteTree deletes a record
DeleteTree(kvObject KV) error
// KVStore returns access to the KV Store
KVStore() store.Store
}
DataStore exported
func NewCustomDataStore ¶
NewCustomDataStore can be used by clients to plugin cusom datatore that adhers to store.Store
func NewDataStore ¶
func NewDataStore(cfg *config.DatastoreCfg) (DataStore, error)
NewDataStore creates a new instance of LibKV data store
type KV ¶
type KV interface {
// Key method lets an object to provide the Key to be used in KV Store
Key() []string
// KeyPrefix method lets an object to return immediate parent key that can be used for tree walk
KeyPrefix() []string
// Value method lets an object to marshal its content to be stored in the KV store
Value() []byte
// SetValue is used by the datastore to set the object's value when loaded from the data store.
SetValue([]byte) error
// Index method returns the latest DB Index as seen by the object
Index() uint64
// SetIndex method allows the datastore to store the latest DB Index into the object
SetIndex(uint64)
// True if the object exists in the datastore, false if it hasn't been stored yet.
// When SetIndex() is called, the object has been stored.
Exists() bool
}
KV Key Value interface used by objects to be part of the DataStore
type MockStore ¶
type MockStore struct {
// contains filtered or unexported fields
}
MockStore exported
func NewMockStore ¶
func NewMockStore() *MockStore
NewMockStore creates a Map backed Datastore that is useful for mocking
func (*MockStore) AtomicDelete ¶
AtomicDelete deletes a value at "key" if the key has not been modified in the meantime, throws an error if this is the case
func (*MockStore) AtomicPut ¶
func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error)
AtomicPut put a value at "key" if the key has not been modified in the meantime, throws an error if this is the case
func (*MockStore) DeleteTree ¶
DeleteTree deletes a range of values at "directory"
func (*MockStore) Get ¶
Get the value at "key", returns the last modified index to use in conjunction to CAS calls