-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
57 lines (48 loc) · 1.02 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
package tracer
const (
DEFAULT_HOPS int = 64
DEFAULT_TIMEOUT_SECONDS int = 5
DEFAULT_MAX_RETRIES int = 2
)
type TracerConfig struct {
MaxHops int
TimeoutSeconds int
MaxRetries int
}
func NewConfig() *TracerConfig {
return &TracerConfig{
MaxHops: DEFAULT_HOPS,
TimeoutSeconds: DEFAULT_TIMEOUT_SECONDS,
MaxRetries: DEFAULT_MAX_RETRIES,
}
}
func (t *TracerConfig) Hops() int {
if t.MaxHops == 0 {
t.MaxHops = DEFAULT_HOPS
}
return t.MaxHops
}
func (t *TracerConfig) Timeout() int {
if t.TimeoutSeconds == 0 {
t.TimeoutSeconds = DEFAULT_TIMEOUT_SECONDS
}
return t.TimeoutSeconds
}
func (t *TracerConfig) Retries() int {
if t.MaxRetries == 0 {
t.MaxRetries = DEFAULT_MAX_RETRIES
}
return t.MaxRetries
}
func (t *TracerConfig) WithHops(h int) *TracerConfig {
t.MaxHops = h
return t
}
func (t *TracerConfig) WithTimeout(to int) *TracerConfig {
t.TimeoutSeconds = to
return t
}
func (t *TracerConfig) WithMaxRetries(n int) *TracerConfig {
t.MaxRetries = n
return t
}