2019-06-12 09:46:20 +03:00
|
|
|
package store
|
2019-06-11 19:20:52 +03:00
|
|
|
|
|
|
|
import (
|
2019-12-16 17:38:51 +03:00
|
|
|
"context"
|
2019-06-11 19:20:52 +03:00
|
|
|
)
|
|
|
|
|
2019-12-16 15:13:18 +03:00
|
|
|
type Options struct {
|
|
|
|
// nodes to connect to
|
|
|
|
Nodes []string
|
|
|
|
// Namespace of the store
|
|
|
|
Namespace string
|
|
|
|
// Prefix of the keys used
|
|
|
|
Prefix string
|
2020-02-03 11:16:02 +03:00
|
|
|
// Suffix of the keys used
|
|
|
|
Suffix string
|
2019-12-16 17:38:51 +03:00
|
|
|
// Alternative options
|
|
|
|
Context context.Context
|
2019-12-16 15:13:18 +03:00
|
|
|
}
|
|
|
|
|
2019-12-16 17:38:51 +03:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
2019-11-01 17:13:21 +03:00
|
|
|
// Nodes is a list of nodes used to back the store
|
2019-12-16 17:38:51 +03:00
|
|
|
func Nodes(a ...string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Nodes = a
|
|
|
|
}
|
2019-06-11 19:20:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prefix sets a prefix to any key ids used
|
2019-12-16 17:38:51 +03:00
|
|
|
func Prefix(p string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Prefix = p
|
|
|
|
}
|
2019-06-11 19:20:52 +03:00
|
|
|
}
|
2019-11-01 17:13:21 +03:00
|
|
|
|
|
|
|
// Namespace offers a way to have multiple isolated
|
|
|
|
// stores in the same backend, if supported.
|
2019-12-16 17:38:51 +03:00
|
|
|
func Namespace(ns string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Namespace = ns
|
|
|
|
}
|
2019-11-01 17:13:21 +03:00
|
|
|
}
|
2020-01-09 01:23:14 +03:00
|
|
|
|
|
|
|
// ReadPrefix uses the key as a prefix
|
|
|
|
func ReadPrefix() ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Prefix = true
|
|
|
|
}
|
|
|
|
}
|
2020-02-03 11:16:02 +03:00
|
|
|
|
|
|
|
// ReadSuffix uses the key as a suffix
|
|
|
|
func ReadSuffix() ReadOption {
|
|
|
|
return func(o *ReadOptions) {
|
|
|
|
o.Suffix = true
|
|
|
|
}
|
|
|
|
}
|