-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
94 lines (82 loc) · 2.03 KB
/
config.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package rcon
import "time"
var DefaultConfig = Config{
DialTimeout: time.Second,
ReadTimeout: 100 * time.Millisecond,
WriteTimeout: 100 * time.Millisecond,
AuthReadTimeout: time.Second,
AuthWriteTimeout: time.Second,
SendBodyMaxSize: 1446,
ReceiveBodyMaxSize: 4096,
MaxOpenCount: 50,
MaxIdleCount: 50,
MaxOpenDuration: 10 * time.Hour,
MaxIdleDuration: 10 * time.Minute,
GCDisabled: false,
GCDelay: time.Second,
}
type Config struct {
Address string
Password string
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
AuthReadTimeout time.Duration
AuthWriteTimeout time.Duration
SendBodyMaxSize int32
ReceiveBodyMaxSize int32
MaxOpenCount int32
MaxIdleCount int32
MaxOpenDuration time.Duration
MaxIdleDuration time.Duration
GCDisabled bool
GCDelay time.Duration
}
var _ option = (*Config)(nil)
func (c Config) Apply(config *Config) {
if c.Address != "" {
config.Address = c.Address
}
if c.Password != "" {
config.Password = c.Password
}
if c.DialTimeout != 0 {
config.DialTimeout = max(0, c.DialTimeout)
}
if c.ReadTimeout != 0 {
config.ReadTimeout = max(0, c.ReadTimeout)
}
if c.WriteTimeout != 0 {
config.WriteTimeout = max(0, c.WriteTimeout)
}
if c.AuthReadTimeout != 0 {
config.AuthReadTimeout = max(0, c.AuthReadTimeout)
}
if c.AuthWriteTimeout != 0 {
config.AuthWriteTimeout = max(0, c.AuthWriteTimeout)
}
if c.SendBodyMaxSize != 0 {
config.SendBodyMaxSize = max(0, c.SendBodyMaxSize)
}
if c.ReceiveBodyMaxSize != 0 {
config.ReceiveBodyMaxSize = max(0, c.ReceiveBodyMaxSize)
}
if c.MaxOpenCount != 0 {
config.MaxOpenCount = max(0, c.MaxOpenCount)
}
if c.MaxIdleCount != 0 {
config.MaxIdleCount = max(0, c.MaxIdleCount)
}
if c.MaxOpenDuration != 0 {
config.MaxOpenDuration = max(0, c.MaxOpenDuration)
}
if c.MaxIdleDuration != 0 {
config.MaxIdleDuration = max(0, c.MaxIdleDuration)
}
if c.GCDisabled {
config.GCDisabled = c.GCDisabled
}
if c.GCDelay != 0 {
config.GCDelay = max(0, c.GCDelay)
}
}