micro/store/options.go

48 lines
832 B
Go
Raw Normal View History

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