-
Notifications
You must be signed in to change notification settings - Fork 3
/
option.go
74 lines (60 loc) · 1.42 KB
/
option.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
74
package etcdcli
import (
"time"
"go.uber.org/zap"
)
// Option set the etcd client options.
type Option func(*options)
type options struct {
dialTimeout time.Duration // 连接超时时间,单位(秒)
username string
password string
isSecure bool
serverNameOverride string // etcd 域名
certFile string // 证书文件路径
autoSyncInterval time.Duration // 自动同步member list的间隔
logger *zap.Logger
}
func defaultOptions() *options {
return &options{
dialTimeout: time.Second * 5,
}
}
func (o *options) apply(opts ...Option) {
for _, opt := range opts {
opt(o)
}
}
// WithDialTimeout set dial timeout
func WithDialTimeout(duration time.Duration) Option {
return func(o *options) {
o.dialTimeout = duration
}
}
// WithAuth set authentication
func WithAuth(username string, password string) Option {
return func(o *options) {
o.username = username
o.password = password
}
}
// WithSecure set tls
func WithSecure(serverNameOverride string, certFile string) Option {
return func(o *options) {
o.isSecure = true
o.serverNameOverride = serverNameOverride
o.certFile = certFile
}
}
// WithAutoSyncInterval set auto sync interval value
func WithAutoSyncInterval(duration time.Duration) Option {
return func(o *options) {
o.autoSyncInterval = duration
}
}
// WithLog set logger
func WithLog(l *zap.Logger) Option {
return func(o *options) {
o.logger = l
}
}