Documentation ¶
Overview ¶
Package store provides the interface for a key-value store with different backends
Index ¶
- Variables
- func Put(b Backend, key string, v interface{}, opts ...PutOption) (bool, error)
- func WithContext(ctx context.Context) interface{ ... }
- func WithErrorHandler(h ErrorFunc) interface{ ... }
- func WithFilter(f FilterFunc) interface{ ... }
- func WithHandler(h HandlerFunc) interface{ ... }
- func WithInsert() interface{ ... }
- func WithKeepAlive(errChan chan<- error) interface{ ... }
- func WithNotifyCreated(c NotifyCallback) interface{ ... }
- func WithPrefix() interface{ ... }
- func WithTTL(ttl time.Duration) interface{ ... }
- func WithUnmarshal(v interface{}) interface{ ... }
- type Backend
- type BackendKeyer
- type DelOption
- type DelOptions
- type Entry
- type ErrorFunc
- type EventMeta
- type FilterFunc
- type GetOption
- type GetOptions
- type HandlerFunc
- type KeyMarshaller
- type KeyOpSetter
- type NotifyCallback
- type Operation
- type PutOption
- type PutOptions
- type WatchOption
- type WatchOptions
- type WatchStarter
- type Watcher
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotFound is returned when key was not found. ErrKeyNotFound = errors.New("key not found") // ErrResponseChannelClosed will be returned if the response channel of the keep-alive is closed ErrResponseChannelClosed = errors.New("keepalive response channel has been closed") )
Functions ¶
func Put ¶
Put is a wrapper around the Backend interface's Put method. This wrapper JSON marhals the interface v and uses the generated byte array as value.
func WithContext ¶
WithContext is an options to set a context for a request.
func WithErrorHandler ¶
func WithErrorHandler(h ErrorFunc) interface { WatchOption }
WithErrorHandler is an option to use an ErrorFunc on each error not returned
func WithFilter ¶ added in v0.3.0
func WithFilter(f FilterFunc) interface { GetOption }
WithFilter is an option to use an FilterFunc on each key-value pair during a Get request.
func WithHandler ¶
func WithHandler(h HandlerFunc) interface { GetOption }
WithHandler is an option to use an HandlerFunc on each key-value pair during a Get request.
func WithInsert ¶
func WithInsert() interface { PutOption }
WithInsert is an option to put a non existing key. If the key already exists, nothing is done and false is returned. If key does not exist key and value are added and true is returned.
func WithKeepAlive ¶ added in v0.1.3
WithKeepAlive is an option to start a keep-alive for a key. The keep-alive will only start if errChan != nil
func WithNotifyCreated ¶
func WithNotifyCreated(c NotifyCallback) interface { WatchOption }
WithNotifyCreated is an option to use a NotifyCallback as soon as the Watch is established and ready to receive events
func WithPrefix ¶
func WithPrefix() interface { GetOption DelOption WatchOption }
WithPrefix is an option to perform a request with prefix.
func WithUnmarshal ¶
func WithUnmarshal(v interface{}) interface { GetOption }
WithUnmarshal unmarshals the byte array in the store into v. It panics if v is not a pointer .
In combination with WithPrefix, v should be a pointer to a slice.
Types ¶
type Backend ¶
type Backend interface { // Put is used to insert or update an entry. // // The entry is added if the key exists or not. // If value is changed, true is returned, false is returned only if // value stays unchanged. // // If WithInsert option is used and the key already // exists, nothing is done and false is returned. If key does not exist // the entry is added and true is returned. Put(*Entry, ...PutOption) (bool, error) // Get is used to fetch an entry. If key is not found and WithPrefix is absent ErrKeyNotFound is // returned. Get(string, ...GetOption) ([]Entry, error) // Delete is used to permanently delte an entry. The number of deleted keys will be returned. Del(string, ...DelOption) (int64, error) // Watch a key Watch(string, Watcher, ...WatchOption) error // WatchChan creates a watcher for a key or prefix and unmarshals events into channel. // The channel elements have to implement the store.KeyOpSetter interface. WatchChan(string, interface{}, chan error, ...WatchOption) (WatchStarter, error) // Close closes the connection. Close() error }
Backend is the interface required for a key value store.
type BackendKeyer ¶ added in v0.1.3
type BackendKeyer interface { Backend RelKey(k string) string AbsKey(k string) string JoinKey(args ...string) string SplitKey(key string) []string KeyLeaf(key string) string }
BackendKeyer interface extends Backend with key handling
type DelOption ¶
type DelOption interface {
SetDelOption(*DelOptions)
}
DelOption is the option interface for Del requests.
type DelOptions ¶
DelOptions represent all possible options for Del requests.
type EventMeta ¶ added in v0.3.0
type EventMeta struct {
// contains filtered or unexported fields
}
EventMeta contains store events meta data.
type FilterFunc ¶ added in v0.3.0
FilterFunc is a function that is called on (each) returned key-value pair during a Get request.
type GetOption ¶
type GetOption interface {
SetGetOption(*GetOptions)
}
GetOption is the option interface for Get requests.
type GetOptions ¶
type GetOptions struct { Prefix bool Filter FilterFunc Handler HandlerFunc Context context.Context Unmarshal *unmarshal }
GetOptions represent all possible options for Get requests.
type HandlerFunc ¶
HandlerFunc is a function that is called on (each) returned key-value pair during a Get request.
type KeyMarshaller ¶ added in v0.3.0
KeyMarshaller sets struct fields from splitted key.
type KeyOpSetter ¶ added in v0.3.0
KeyOpSetter interface.
type NotifyCallback ¶
type NotifyCallback func()
NotifyCallback is a function that is called after a watch create event is received.
type PutOption ¶
type PutOption interface {
SetPutOption(*PutOptions)
}
PutOption is the option interface for Put requests.
type PutOptions ¶
type PutOptions struct { Context context.Context TTL time.Duration ErrChan chan<- error Insert bool }
PutOptions represent all possible options for Put requests.
type WatchOption ¶
type WatchOption interface {
SetWatchOption(*WatchOptions)
}
WatchOption is the option interface for watchers.
type WatchOptions ¶
type WatchOptions struct { Prefix bool Context context.Context NotifyCreated NotifyCallback ErrorHandler ErrorFunc }
WatchOptions represent all possible options for watchers.
Directories ¶
Path | Synopsis |
---|---|
Package etcd implements the store.Backend interface for the etcd
|
Package etcd implements the store.Backend interface for the etcd |
Package hash implements the store.Backend interface for a hash map
|
Package hash implements the store.Backend interface for a hash map |
internal
|
|
common
Package common contains helper methods used by all store implementations.
|
Package common contains helper methods used by all store implementations. |