change store options

This commit is contained in:
Asim Aslam
2019-12-16 14:38:51 +00:00
parent e8e112144f
commit 59751c02e6
8 changed files with 156 additions and 179 deletions

View File

@@ -1,7 +1,7 @@
package store
import (
"github.com/micro/go-micro/config/options"
"context"
)
type Options struct {
@@ -11,20 +11,30 @@ type Options struct {
Namespace string
// Prefix of the keys used
Prefix string
// Alternative options
Context context.Context
}
type Option func(o *Options)
// Nodes is a list of nodes used to back the store
func Nodes(a ...string) options.Option {
return options.WithValue("store.nodes", a)
func Nodes(a ...string) Option {
return func(o *Options) {
o.Nodes = a
}
}
// Prefix sets a prefix to any key ids used
func Prefix(p string) options.Option {
return options.WithValue("store.prefix", p)
func Prefix(p string) Option {
return func(o *Options) {
o.Prefix = p
}
}
// Namespace offers a way to have multiple isolated
// stores in the same backend, if supported.
func Namespace(n string) options.Option {
return options.WithValue("store.namespace", n)
func Namespace(ns string) Option {
return func(o *Options) {
o.Namespace = ns
}
}