-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
78 lines (67 loc) · 1.41 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
72
73
74
75
76
77
78
package lookout
import (
"time"
"github.com/ipni/lookout/check"
"github.com/ipni/lookout/sample"
)
type (
Option func(*options) error
options struct {
metricsListenAddr string
checkInterval *time.Ticker
checkersParallelism int
samplersParallelism int
checkers []check.Checker
samplers []sample.Sampler
}
)
func newOptions(o ...Option) (*options, error) {
opts := options{
metricsListenAddr: "0.0.0.0:40080",
checkInterval: time.NewTicker(5 * time.Minute),
checkersParallelism: 10,
samplersParallelism: 10,
}
for _, apply := range o {
if err := apply(&opts); err != nil {
return nil, err
}
}
return &opts, nil
}
func WithMetricsListenAddr(a string) Option {
return func(o *options) error {
o.metricsListenAddr = a
return nil
}
}
func WithCheckers(c ...check.Checker) Option {
return func(o *options) error {
o.checkers = c
return nil
}
}
func WithSamplers(s ...sample.Sampler) Option {
return func(o *options) error {
o.samplers = s
return nil
}
}
func WithCheckInterval(i time.Duration) Option {
return func(o *options) error {
o.checkInterval = time.NewTicker(i)
return nil
}
}
func WithCheckersParallelism(p int) Option {
return func(o *options) error {
o.checkersParallelism = p
return nil
}
}
func WithSamplersParallelism(p int) Option {
return func(o *options) error {
o.samplersParallelism = p
return nil
}
}