-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.go
62 lines (52 loc) · 1.33 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
package apollo
import (
"context"
"github.com/stack-labs/stack-rpc/pkg/config/source"
)
type appIDKey struct{}
type clusterKey struct{}
type addrKey struct{}
type namespacesKey struct{}
type isBackupConfigKey struct{}
type secretKey struct{}
func AppID(id string) source.Option {
return func(o *source.Options) {
prepareCtx(o)
o.Context = context.WithValue(o.Context, appIDKey{}, id)
}
}
func Cluster(cluster string) source.Option {
return func(o *source.Options) {
prepareCtx(o)
o.Context = context.WithValue(o.Context, clusterKey{}, cluster)
}
}
func Addr(addr string) source.Option {
return func(o *source.Options) {
prepareCtx(o)
o.Context = context.WithValue(o.Context, addrKey{}, addr)
}
}
func Namespaces(namespaces string) source.Option {
return func(o *source.Options) {
prepareCtx(o)
o.Context = context.WithValue(o.Context, namespacesKey{}, namespaces)
}
}
func IsBackupConfig(isBackupConfig bool) source.Option {
return func(o *source.Options) {
prepareCtx(o)
o.Context = context.WithValue(o.Context, isBackupConfigKey{}, isBackupConfig)
}
}
func Secret(secret string) source.Option {
return func(o *source.Options) {
prepareCtx(o)
o.Context = context.WithValue(o.Context, secretKey{}, secret)
}
}
func prepareCtx(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
}