forked from bkono/go-config
/
options.go
40 lines (34 loc) · 871 Bytes
/
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
package configmap
import (
"context"
"github.com/micro/go-config/source"
)
type configPathKey struct{}
type prefixKey struct{}
type nameKey struct{}
type namespaceKey struct{}
func WithNamespace(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, namespaceKey{}, s)
}
}
func WithName(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, nameKey{}, s)
}
}
// WithConfigPath option for setting a custom path to kubeconfig
func WithConfigPath(s string) source.Option {
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, configPathKey{}, s)
}
}