Documentation ¶
Index ¶
- Variables
- type Driver
- func (d *Driver) Connect(address string, password string) error
- func (d *Driver) Delete(ctx context.Context, key string) error
- func (d *Driver) Disconnect() error
- func (d *Driver) Get(ctx context.Context, key string, t Type) (value interface{}, err error)
- func (d *Driver) GetMap(ctx context.Context, key string) (map[string]interface{}, error)
- func (d *Driver) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- func (d *Driver) SetForever(ctx context.Context, key string, value interface{}) error
- func (d *Driver) SetMap(ctx context.Context, key string, value map[string]interface{}, ...) error
- func (d *Driver) SetMapWithEnvDuration(ctx context.Context, key string, value map[string]interface{}, ...) error
- func (d *Driver) SetWithEnvDuration(ctx context.Context, key string, value interface{}, expirationEnvVar string, ...) error
- type Interface
- type MockDriver
- func (kvs *MockDriver) Connect(address string, password string) error
- func (kvs *MockDriver) Delete(ctx context.Context, key string) error
- func (kvs *MockDriver) Disconnect() error
- func (kvs *MockDriver) Get(ctx context.Context, key string, t Type) (interface{}, error)
- func (kvs *MockDriver) GetMap(ctx context.Context, key string) (map[string]interface{}, error)
- func (kvs *MockDriver) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
- func (kvs *MockDriver) SetForever(ctx context.Context, key string, value interface{}) error
- func (kvs *MockDriver) SetMap(ctx context.Context, key string, value map[string]interface{}, ...) error
- func (kvs *MockDriver) SetMapWithEnvDuration(ctx context.Context, key string, value map[string]interface{}, ...) error
- func (kvs *MockDriver) SetWithEnvDuration(ctx context.Context, key string, value interface{}, expirationEnvVar string, ...) error
- type Type
Constants ¶
This section is empty.
Variables ¶
var ErrKeyNotFound = errors.New("key not present in kvs")
ErrKeyNotFound is self explanatory
var KeyAlreadyExists = errors.New("key already present in kvs")
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver implements the keyvaluestore interface
func (*Driver) Connect ¶
Connect opens the connection to the keyvaluestore
Return: error, returns a potential error
func (*Driver) Delete ¶
Delete deletes the key value pair from the key value store
context: context.Context, the context in which the delete operation should take place key: string, the key for which to delete the value from the key value store Returns: a possible error
func (*Driver) Disconnect ¶
Disconnect disconnects from the keyvaluestore
Return: error, returns a potential error
func (*Driver) Get ¶
Get gets the value for the given key
ctx: context.Context, the context in which to perform the get operation key: string, the key for which to get the value Returns the value retrieved from the keyvaluestore
func (*Driver) GetMap ¶
GetMap gets the map for the given key
ctx: context.Context, the context in which to perform the get operation key: string, the key for which to get the value Returns the map retrieved from the keyvaluestore
func (*Driver) Set ¶
func (d *Driver) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error
Set sets the value for the given key
ctx: context.Context, the context in which to perform the set operation key: string, the key for which you want to store the value value: interface{}, the value you want to store expiration: time.Duration, the expiration time of the value Return: an error if something goes wrong
func (*Driver) SetForever ¶
Set sets the value for the given key
ctx: context.Context, the context in which to perform the set operation key: string, the key for which you want to store the value value: interface{}, the value you want to store Return: an error if something goes wrong
func (*Driver) SetMap ¶
func (d *Driver) SetMap(ctx context.Context, key string, value map[string]interface{}, expiration time.Duration) error
SetMap sets the map for the given key
ctx: context.Context, the context in which to perform the set operation key: string, the key for which you want to store the value value: map[string]interface{}, the value you want to store expiration: time.Duration, the expiration time of the value Return: an error if something goes wrong
func (*Driver) SetMapWithEnvDuration ¶
func (d *Driver) SetMapWithEnvDuration(ctx context.Context, key string, value map[string]interface{}, expirationEnvVar string, expirationFallback time.Duration) error
SetMapWithEnvDuration sets the map for the given key with the expiration time set by an environment variable
ctx: context.Context, the context in which to perform the set operation key: string, the key for which you want to store the value value: map[string]interface{}, the value you want to store expirationEnvVar: string, the environment variable that contains the expiration time expirationFallback: time.Duration, the fallback expiration time Return: an error if something goes wrong
func (*Driver) SetWithEnvDuration ¶
func (d *Driver) SetWithEnvDuration(ctx context.Context, key string, value interface{}, expirationEnvVar string, expirationFallback time.Duration) error
SetMapWithEnvDuration sets the map for the given key with the expiration time set by an environment variable
ctx: context.Context, the context in which to perform the set operation key: string, the key for which you want to store the value value: map[string]interface{}, the value you want to store expirationEnvVar: string, the environment variable that contains the expiration time expirationFallback: time.Duration, the fallback expiration time Return: an error if something goes wrong
type Interface ¶
type Interface interface { Connect(address string, password string) error GetMap(ctx context.Context, key string) (value map[string]interface{}, err error) Get(ctx context.Context, key string, t Type) (value interface{}, err error) SetForever(ctx context.Context, key string, value interface{}) error SetMap(ctx context.Context, key string, value map[string]interface{}, expiration time.Duration) error Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error SetMapWithEnvDuration(ctx context.Context, key string, value map[string]interface{}, expirationEnvVar string, expirationFallback time.Duration) error SetWithEnvDuration(ctx context.Context, key string, value interface{}, expirationEnvVar string, expirationFallback time.Duration) error Delete(ctx context.Context, key string) error Disconnect() error // contains filtered or unexported methods }
Interface is an interface for a key value storage
func NewDriver ¶
func NewDriver() Interface
NewDriver creates a new keyvaluestore driver
Return: Interface, returns a new driver
func NewMockDriver ¶
func NewMockDriver() Interface
NewMockDriver creates a key value store driver (mock)
Return: the interface for the new mock driver
type MockDriver ¶
type MockDriver struct {
Data map[string]interface{}
}
A MockDriver implements methods to set key-value data (mock)
func (*MockDriver) Connect ¶
func (kvs *MockDriver) Connect(address string, password string) error
Connect connects to the keyvaluestore
Return: if there's an error
func (*MockDriver) Delete ¶
func (kvs *MockDriver) Delete(ctx context.Context, key string) error
Delete deletes the key value pair from the key value store (mock)
ctx: context.Context, the context for the driver key: string, the key for the driver Return: if there's an error
func (*MockDriver) Disconnect ¶
func (kvs *MockDriver) Disconnect() error
Disconnect disconnects from the key value store (mock)
Return: if there's an error
func (*MockDriver) Get ¶
Get gets the value for the supplied key from the key value store (mock)
ctx: context.Context, the context for the driver key: string, the key for the driver t: Type, the type of the driver Return: (interface{}, error), the interface and any error that occurred
func (*MockDriver) SetForever ¶
func (kvs *MockDriver) SetForever(ctx context.Context, key string, value interface{}) error
Set sets a key to a value in the key value store. Expects a non-pointer as value. (mock)
ctx: context.Context, the context for the driver key: string, the key for the driver value: interface{}, the value for the driver Return: if there's an error