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