forked from itspage/go-platform
/
options.go
73 lines (60 loc) · 1.36 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package kv
import (
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/server"
"golang.org/x/net/context"
)
type serviceKey struct{}
type Options struct {
// Servers that store values for access
Servers []string
// Limit the scope of queries to a namespace
// In the case of platform it essentially
// means the topic we pub to for "gossip"
// For memcache and redis it could be key/prefix
Namespace string
// Number of replicas
// Default is 1 ofcourse
Replicas int
// Use a service rather than gossip
Service bool
// Whether handlers should be internal
Internal bool
// Replace with go-micro.Service?
Client client.Client
Server server.Server
// Alternative options set using Context
Context context.Context
}
func Servers(s ...string) Option {
return func(o *Options) {
o.Servers = s
}
}
func Namespace(ns string) Option {
return func(o *Options) {
o.Namespace = ns
}
}
func Client(c client.Client) Option {
return func(o *Options) {
o.Client = c
}
}
func Server(s server.Server) Option {
return func(o *Options) {
o.Server = s
}
}
// Internal specifies whether to use advertise handlers to discovery
func Internal(b bool) Option {
return func(o *Options) {
o.Internal = b
}
}
// Service specifies whether to use the KV service. Defaults to false.
func Service(b bool) Option {
return func(o *Options) {
o.Service = b
}
}