-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
executable file
·71 lines (58 loc) · 1.26 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
package nacos
import "github.com/nacos-group/nacos-sdk-go/v2/common/constant"
const (
allEths = "0.0.0.0"
envPodIP = "POD_IP"
)
// options
type Options struct {
ListenOn string
ServiceName string
Prefix string
Weight float64
Cluster string
Group string
Metadata map[string]string
ServerConfig []constant.ServerConfig
ClientConfig *constant.ClientConfig
}
type Option func(*Options)
func NewNacosConfig(serviceName, listenOn string, sc []constant.ServerConfig, cc *constant.ClientConfig, opts ...Option) *Options {
options := &Options{
ServiceName: serviceName,
ListenOn: listenOn,
ServerConfig: sc,
ClientConfig: cc,
Weight: 1.0,
Metadata: make(map[string]string),
}
for _, opt := range opts {
opt(options)
}
return options
}
func WithPrefix(prefix string) Option {
return func(o *Options) {
o.Prefix = prefix
}
}
func WithWeight(weight float64) Option {
return func(o *Options) {
o.Weight = weight
}
}
func WithCluster(cluster string) Option {
return func(o *Options) {
o.Cluster = cluster
}
}
func WithGroup(group string) Option {
return func(o *Options) {
o.Group = group
}
}
func WithMetadata(metadata map[string]string) Option {
return func(o *Options) {
o.Metadata = metadata
}
}