Documentation ¶
Overview ¶
Package unikv provides a memory kv storage middleware
Index ¶
- Constants
- Variables
- func ConcatPrefix(prefix string, str string) string
- func DriverLoadContext(ctx DriverContextRaw, dest interface{}) error
- func IsErrNotFound(err error) bool
- func RegisterDriver(driver *DriverDescriptor)
- func ReloadConfigure()
- func TrimPrefix(prefix string, str string) string
- type Bucket
- func (b *Bucket) Close() error
- func (b *Bucket) Get(key interface{}, dest interface{}) error
- func (b *Bucket) GetInt(key interface{}) (int, error)
- func (b *Bucket) GetString(key interface{}) (string, error)
- func (b *Bucket) List() ([]Key, error)
- func (b *Bucket) Put(key interface{}, value interface{}) error
- func (b *Bucket) PutInt(key interface{}, value int) error
- func (b *Bucket) PutString(key interface{}, str string) error
- func (b *Bucket) Unset(key interface{}) error
- type Configure
- type ConfigureBuckets
- type ConfigureDefault
- type ConfigureNamespaces
- type Driver
- type DriverContextRaw
- type DriverDescriptor
- type Key
- type KeyString
- type Namespace
Constants ¶
const ConfigureEnvName = "UNIKV_CONFIGURE"
ConfigureEnvName is the name of the environment variable of unikv's configure file
const DefaultConfigureFile = "unikv.yml"
DefaultConfigureFile is the default filename of unikv's configure
const DefaultDriver = "memory"
DefaultDriver determines the default driver to use when not specified
The driver must be without context
const PrefixSeparator = ":"
PrefixSeparator separates different parts of a key's prefix
const Version = 1
Version declares the api version of unikv
Variables ¶
var ErrNotFound = fmt.Errorf("ErrNotFound")
ErrNotFound is thrown when trying to access an unset key
var KeyNil = KeyString("(unikv_nil)")
KeyNil is blanck key
Functions ¶
func ConcatPrefix ¶
ConcatPrefix concats two prefixes together
func DriverLoadContext ¶
func DriverLoadContext(ctx DriverContextRaw, dest interface{}) error
DriverLoadContext loads raw context into a structure
func IsErrNotFound ¶
IsErrNotFound checks if an error is unikv.ErrNotFound
func RegisterDriver ¶
func RegisterDriver(driver *DriverDescriptor)
RegisterDriver registers a new driver
func TrimPrefix ¶ added in v0.3.0
TrimPrefix trims the prefix of the given string
Types ¶
type Bucket ¶
type Bucket struct { Name string Prefix string NamespaceName string Driver Driver // contains filtered or unexported fields }
Bucket is a unikv store bucket
type Configure ¶
type Configure struct { Separator string `yaml:"separator" json:"separator"` Default *ConfigureDefault `yaml:"default" json:"default"` Namespaces map[string]*ConfigureNamespaces `yaml:"namespaces" json:"namespaces"` }
Configure is unikv's configure structure
func (*Configure) GetNamespace ¶
func (c *Configure) GetNamespace(name string) (*ConfigureNamespaces, bool)
GetNamespace returns a specificated namespace from the list
func (*Configure) GetNamespaceList ¶
GetNamespaceList returns the list of namespaces
type ConfigureBuckets ¶
type ConfigureBuckets struct { Prefix string `yaml:"prefix" json:"prefix"` Driver string `yaml:"driver" json:"driver"` Context DriverContextRaw `yaml:"context" json:"context"` }
ConfigureBuckets is the bucket segment in unikv's configure
type ConfigureDefault ¶
type ConfigureDefault struct { Driver string `yaml:"driver" json:"driver"` Context DriverContextRaw `yaml:"context" json:"context"` }
ConfigureDefault is the default segment in unikv's configure
type ConfigureNamespaces ¶
type ConfigureNamespaces struct { Prefix string `yaml:"prefix" json:"prefix"` Buckets map[string]*ConfigureBuckets `yaml:"buckets" json:"buckets"` }
ConfigureNamespaces is the namespace segment in unikv's configure
func (*ConfigureNamespaces) GetBucket ¶
func (c *ConfigureNamespaces) GetBucket(name string) (*ConfigureBuckets, bool)
GetBucket returns the bucket
func (*ConfigureNamespaces) GetBucketList ¶
func (c *ConfigureNamespaces) GetBucketList() []string
GetBucketList returns bucket list
type Driver ¶
type Driver interface { Get(key string) (string, error) Put(key string, data string) error Unset(key string) error List() (interface{}, error) // interface{} should be []unikv.Key or []string Close() error }
Driver declares a unikv storage driver
type DriverContextRaw ¶
type DriverContextRaw map[string]interface{}
DriverContextRaw contains the raw map of driver configuration passed in within unikv configure
type DriverDescriptor ¶
type DriverDescriptor struct { Name string Constructor func(prefix string, ctx DriverContextRaw) (Driver, error) }
DriverDescriptor is used for storing meta information of the driver
func (*DriverDescriptor) Construct ¶
func (ds *DriverDescriptor) Construct(prefix string, ctx DriverContextRaw) (Driver, error)
Construct a new driver instance