Documentation ¶
Index ¶
- Constants
- Variables
- type Backend
- type Config
- type Consul
- func (s *Consul) AtomicDelete(key string, previous *KVPair) (bool, error)
- func (s *Consul) AtomicPut(key string, value []byte, previous *KVPair, options *WriteOptions) (bool, *KVPair, error)
- func (s *Consul) Close()
- func (s *Consul) Delete(key string) error
- func (s *Consul) DeleteTree(prefix string) error
- func (s *Consul) Exists(key string) (bool, error)
- func (s *Consul) Get(key string) (*KVPair, error)
- func (s *Consul) List(prefix string) ([]*KVPair, error)
- func (s *Consul) NewLock(key string, options *LockOptions) (Locker, error)
- func (s *Consul) Put(key string, value []byte, opts *WriteOptions) error
- func (s *Consul) Watch(key string, stopCh <-chan struct{}) (<-chan *KVPair, error)
- func (s *Consul) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*KVPair, error)
- type Etcd
- func (s *Etcd) AtomicDelete(key string, previous *KVPair) (bool, error)
- func (s *Etcd) AtomicPut(key string, value []byte, previous *KVPair, options *WriteOptions) (bool, *KVPair, error)
- func (s *Etcd) Close()
- func (s *Etcd) Delete(key string) error
- func (s *Etcd) DeleteTree(prefix string) error
- func (s *Etcd) Exists(key string) (bool, error)
- func (s *Etcd) Get(key string) (*KVPair, error)
- func (s *Etcd) List(prefix string) ([]*KVPair, error)
- func (s *Etcd) NewLock(key string, options *LockOptions) (Locker, error)
- func (s *Etcd) Put(key string, value []byte, opts *WriteOptions) error
- func (s *Etcd) Watch(key string, stopCh <-chan struct{}) (<-chan *KVPair, error)
- func (s *Etcd) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*KVPair, error)
- type Initialize
- type KVPair
- type LockOptions
- type Locker
- type Mock
- func (s *Mock) AtomicDelete(key string, previous *KVPair) (bool, error)
- func (s *Mock) AtomicPut(key string, value []byte, previous *KVPair, opts *WriteOptions) (bool, *KVPair, error)
- func (s *Mock) Close()
- func (s *Mock) Delete(key string) error
- func (s *Mock) DeleteTree(prefix string) error
- func (s *Mock) Exists(key string) (bool, error)
- func (s *Mock) Get(key string) (*KVPair, error)
- func (s *Mock) List(prefix string) ([]*KVPair, error)
- func (s *Mock) NewLock(key string, options *LockOptions) (Locker, error)
- func (s *Mock) Put(key string, value []byte, opts *WriteOptions) error
- func (s *Mock) Watch(key string, stopCh <-chan struct{}) (<-chan *KVPair, error)
- func (s *Mock) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*KVPair, error)
- type MockLock
- type Store
- func InitializeConsul(endpoints []string, options *Config) (Store, error)
- func InitializeEtcd(addrs []string, options *Config) (Store, error)
- func InitializeMock(endpoints []string, options *Config) (Store, error)
- func InitializeZookeeper(endpoints []string, options *Config) (Store, error)
- func NewStore(backend Backend, addrs []string, options *Config) (Store, error)
- type WatchCallback
- type WriteOptions
- type Zookeeper
- func (s *Zookeeper) AtomicDelete(key string, previous *KVPair) (bool, error)
- func (s *Zookeeper) AtomicPut(key string, value []byte, previous *KVPair, _ *WriteOptions) (bool, *KVPair, error)
- func (s *Zookeeper) Close()
- func (s *Zookeeper) Delete(key string) error
- func (s *Zookeeper) DeleteTree(prefix string) error
- func (s *Zookeeper) Exists(key string) (bool, error)
- func (s *Zookeeper) Get(key string) (*KVPair, error)
- func (s *Zookeeper) List(prefix string) ([]*KVPair, error)
- func (s *Zookeeper) NewLock(key string, options *LockOptions) (Locker, error)
- func (s *Zookeeper) Put(key string, value []byte, opts *WriteOptions) error
- func (s *Zookeeper) Watch(key string, stopCh <-chan struct{}) (<-chan *KVPair, error)
- func (s *Zookeeper) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*KVPair, error)
Constants ¶
const ( // MOCK backend MOCK Backend = "mock" // CONSUL backend CONSUL = "consul" // ETCD backend ETCD = "etcd" // ZK backend ZK = "zk" )
const ( // DefaultWatchWaitTime is how long we block for at a time to check if the // watched key has changed. This affects the minimum time it takes to // cancel a watch. DefaultWatchWaitTime = 15 * time.Second )
Variables ¶
var ( // ErrInvalidTTL is a specific error to consul ErrInvalidTTL = errors.New("Invalid TTL, please change the value to the miminum allowed ttl for the chosen store") // ErrNotSupported is exported ErrNotSupported = errors.New("Backend storage not supported yet, please choose another one") // ErrNotImplemented is exported ErrNotImplemented = errors.New("Call not implemented in current backend") // ErrNotReachable is exported ErrNotReachable = errors.New("Api not reachable") // ErrCannotLock is exported ErrCannotLock = errors.New("Error acquiring the lock") // ErrWatchDoesNotExist is exported ErrWatchDoesNotExist = errors.New("No watch found for specified key") // ErrKeyModified is exported ErrKeyModified = errors.New("Unable to complete atomic operation, key modified") // ErrKeyNotFound is exported ErrKeyNotFound = errors.New("Key not found in store") // ErrPreviousNotSpecified is exported ErrPreviousNotSpecified = errors.New("Previous K/V pair should be provided for the Atomic operation") )
Functions ¶
This section is empty.
Types ¶
type Consul ¶
Consul embeds the client and watches
func (*Consul) 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 (*Consul) AtomicPut ¶
func (s *Consul) AtomicPut(key string, value []byte, previous *KVPair, options *WriteOptions) (bool, *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 (*Consul) DeleteTree ¶
DeleteTree deletes a range of keys based on prefix
func (*Consul) Get ¶
Get the value at "key", returns the last modified index to use in conjunction to CAS calls
func (*Consul) NewLock ¶
func (s *Consul) NewLock(key string, options *LockOptions) (Locker, error)
NewLock returns a handle to a lock struct which can be used to acquire and release the mutex.
func (*Consul) Put ¶
func (s *Consul) Put(key string, value []byte, opts *WriteOptions) error
Put a value at "key"
func (*Consul) Watch ¶
Watch changes on a key. Returns a channel that will receive changes or an error. Upon creating a watch, the current value will be sent to the channel. Providing a non-nil stopCh can be used to stop watching.
type Etcd ¶
type Etcd struct {
// contains filtered or unexported fields
}
Etcd embeds the client
func (*Etcd) 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 (*Etcd) AtomicPut ¶
func (s *Etcd) AtomicPut(key string, value []byte, previous *KVPair, options *WriteOptions) (bool, *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 (*Etcd) DeleteTree ¶
DeleteTree deletes a range of keys based on prefix
func (*Etcd) Get ¶
Get the value at "key", returns the last modified index to use in conjunction to CAS calls
func (*Etcd) NewLock ¶
func (s *Etcd) NewLock(key string, options *LockOptions) (Locker, error)
NewLock returns a handle to a lock struct which can be used to acquire and release the mutex.
func (*Etcd) Put ¶
func (s *Etcd) Put(key string, value []byte, opts *WriteOptions) error
Put a value at "key"
func (*Etcd) Watch ¶
Watch changes on a key. Returns a channel that will receive changes or an error. Upon creating a watch, the current value will be sent to the channel. Providing a non-nil stopCh can be used to stop watching.
type Initialize ¶
Initialize creates a new Store object, initializing the client
type LockOptions ¶
type LockOptions struct { Value []byte // Optional, value to associate with the lock TTL time.Duration // Optional, expiration ttl associated with the lock }
LockOptions contains optional request parameters
type Locker ¶
Locker provides locking mechanism on top of the store. Similar to `sync.Lock` except it may return errors.
type Mock ¶
type Mock struct { mock.Mock // Endpoints passed to InitializeMock Endpoints []string // Options passed to InitializeMock Options *Config }
Mock store. Mocks all Store functions using testify.Mock.
func (*Mock) AtomicDelete ¶
AtomicDelete mock
func (*Mock) AtomicPut ¶
func (s *Mock) AtomicPut(key string, value []byte, previous *KVPair, opts *WriteOptions) (bool, *KVPair, error)
AtomicPut mock
func (*Mock) NewLock ¶
func (s *Mock) NewLock(key string, options *LockOptions) (Locker, error)
NewLock mock
type Store ¶
type Store interface { // Put a value at the specified key Put(key string, value []byte, options *WriteOptions) error // Get a value given its key Get(key string) (*KVPair, error) // Delete the value at the specified key Delete(key string) error // Verify if a Key exists in the store Exists(key string) (bool, error) // Watch changes on a key. // Returns a channel that will receive changes or an error. // Upon creating a watch, the current value will be sent to the channel. // Providing a non-nil stopCh can be used to stop watching. Watch(key string, stopCh <-chan struct{}) (<-chan *KVPair, error) // WatchTree watches changes on a "directory" // Returns a channel that will receive changes or an error. // Upon creating a watch, the current value will be sent to the channel. // Providing a non-nil stopCh can be used to stop watching. WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*KVPair, error) // CreateLock for a given key. // The returned Locker is not held and must be acquired with `.Lock`. // value is optional. NewLock(key string, options *LockOptions) (Locker, error) // List the content of a given prefix List(prefix string) ([]*KVPair, error) // DeleteTree deletes a range of keys based on prefix DeleteTree(prefix string) error // Atomic operation on a single value AtomicPut(key string, value []byte, previous *KVPair, options *WriteOptions) (bool, *KVPair, error) // Atomic delete of a single value AtomicDelete(key string, previous *KVPair) (bool, error) // Close the store connection Close() }
Store represents the backend K/V storage Each store should support every call listed here. Or it couldn't be implemented as a K/V backend for libkv
func InitializeConsul ¶
InitializeConsul creates a new Consul client given a list of endpoints and optional tls config
func InitializeEtcd ¶
InitializeEtcd creates a new Etcd client given a list of endpoints and optional tls config
func InitializeMock ¶
InitializeMock creates a Mock store.
func InitializeZookeeper ¶
InitializeZookeeper creates a new Zookeeper client given a list of endpoints and optional tls config
type WatchCallback ¶
type WatchCallback func(entries ...*KVPair)
WatchCallback is used for watch methods on keys and is triggered on key change
type WriteOptions ¶
WriteOptions contains optional request parameters
type Zookeeper ¶
type Zookeeper struct {
// contains filtered or unexported fields
}
Zookeeper embeds the zookeeper client
func (*Zookeeper) 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 (*Zookeeper) AtomicPut ¶
func (s *Zookeeper) AtomicPut(key string, value []byte, previous *KVPair, _ *WriteOptions) (bool, *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 (*Zookeeper) DeleteTree ¶
DeleteTree deletes a range of keys based on prefix
func (*Zookeeper) Get ¶
Get the value at "key", returns the last modified index to use in conjunction to CAS calls
func (*Zookeeper) NewLock ¶
func (s *Zookeeper) NewLock(key string, options *LockOptions) (Locker, error)
NewLock returns a handle to a lock struct which can be used to acquire and release the mutex.
func (*Zookeeper) Put ¶
func (s *Zookeeper) Put(key string, value []byte, opts *WriteOptions) error
Put a value at "key"
func (*Zookeeper) Watch ¶
Watch changes on a key. Returns a channel that will receive changes or an error. Upon creating a watch, the current value will be sent to the channel. Providing a non-nil stopCh can be used to stop watching.