forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
65 lines (53 loc) · 1.16 KB
/
opts.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
package monitoring
// Option type for passing additional options to NewRegistry.
type Option func(options) options
type options struct {
publishExpvar bool
mode Mode
}
var defaultOptions = options{
publishExpvar: false,
mode: Full,
}
// PublishExpvar enables publishing all registered variables via expvar interface.
// Note: expvar does not allow removal of any stats.
func PublishExpvar(o options) options {
o.publishExpvar = true
return o
}
// IgnorePublishExpvar disables publishing expvar variables in a sub-registry.
func IgnorePublishExpvar(o options) options {
o.publishExpvar = false
return o
}
func Report(o options) options {
o.mode = Reported
return o
}
func varOpts(regOpts *options, opts []Option) options {
O := defaultOptions
if regOpts != nil {
O = *regOpts
}
for _, opt := range opts {
O = opt(O)
}
return O
}
func applyOpts(in *options, opts []Option) *options {
if len(opts) == 0 {
return ensureOptions(in)
}
tmp := *ensureOptions(in)
for _, opt := range opts {
tmp = opt(tmp)
}
return &tmp
}
func ensureOptions(in *options) *options {
if in != nil {
return in
}
tmp := defaultOptions
return &tmp
}