-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientoptions.go
More file actions
60 lines (48 loc) · 1.5 KB
/
clientoptions.go
File metadata and controls
60 lines (48 loc) · 1.5 KB
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
package envector
import "time"
const (
defaultDialTimeout = 3 * time.Second
defaultKeepaliveTime = 30 * time.Second
defaultKeepaliveTimeout = 10 * time.Second
defaultMaxMsgSize = 100 * 1024 * 1024
)
type clientOptions struct {
Address string
AccessToken string
Insecure bool
DialTimeout time.Duration
KeepaliveTime time.Duration
KeepaliveTimeout time.Duration
MaxMsgSize int
}
func defaultClientOptions() clientOptions {
return clientOptions{
DialTimeout: defaultDialTimeout,
KeepaliveTime: defaultKeepaliveTime,
KeepaliveTimeout: defaultKeepaliveTimeout,
MaxMsgSize: defaultMaxMsgSize,
}
}
// ClientOption configures NewClient. Apply via the With* helpers below.
type ClientOption func(*clientOptions)
func WithAddress(addr string) ClientOption {
return func(o *clientOptions) { o.Address = addr }
}
func WithAccessToken(token string) ClientOption {
return func(o *clientOptions) { o.AccessToken = token }
}
func WithInsecure() ClientOption {
return func(o *clientOptions) { o.Insecure = true }
}
func WithDialTimeout(d time.Duration) ClientOption {
return func(o *clientOptions) { o.DialTimeout = d }
}
func WithKeepaliveTime(d time.Duration) ClientOption {
return func(o *clientOptions) { o.KeepaliveTime = d }
}
func WithKeepaliveTimeout(d time.Duration) ClientOption {
return func(o *clientOptions) { o.KeepaliveTimeout = d }
}
func WithMaxMsgSize(n int) ClientOption {
return func(o *clientOptions) { o.MaxMsgSize = n }
}