-
Notifications
You must be signed in to change notification settings - Fork 4
/
builder_options.go
103 lines (83 loc) · 3.03 KB
/
builder_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package cadre
import (
"errors"
"os"
"github.com/moderntv/cadre/metrics"
"github.com/moderntv/cadre/status"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"
"golang.org/x/net/context"
)
type Option func(*Builder) error
// WithContext supplies custom context for the cadre server. This is useful for graceful shutdown.
func WithContext(ctx context.Context) Option {
return func(options *Builder) error {
options.ctx = ctx
return nil
}
}
// WithFinisher adds a callback to be called for various signals (SIGINT, SIGTERM by default) which can be optionally set.
func WithFinisher(cb Finisher, handledSigs ...os.Signal) Option {
return func(options *Builder) error {
if options.finisherCallback != nil {
return errors.New("finisher already registered")
}
options.finisherCallback = cb
if len(handledSigs) > 0 {
options.handledSigs = handledSigs
}
return nil
}
}
// WithLogger allows configuring cadre with custom zerolog logger.
// If not used Cadre will be configured with zerolog.Nop().
func WithLogger(logger zerolog.Logger) Option {
return func(options *Builder) error {
options.logger = logger
return nil
}
}
// WithStatus allows replacing the default status with a custom pre-configured one.
func WithStatus(status *status.Status) Option {
return func(options *Builder) error {
options.status = status
return nil
}
}
// WithStatusListeningAddress is meant to configure cadre to use
// a separate http server for status endpoint - useful for putting it behind firewall.
// Default is to use the first HTTP server's listening address merging them together. This may cause problems
// when a conflicting route is configured.
func WithStatusListeningAddress(serverListeningAddress string) Option {
return func(options *Builder) error {
options.statusHTTPServerAddr = serverListeningAddress
return nil
}
}
// WithMetricsRegistry allows replacing the default metrics registry with a custom pre-configured one.
// If used, the prometheus registry from metrics Registry will replace the default prometheus registry.
// Do not use with WithPrometheusRegistry.
func WithMetricsRegistry(metrics *metrics.Registry) Option {
return func(options *Builder) error {
options.metrics = metrics
return nil
}
}
// WithPrometheusRegistry configures cadre to use a specific prometheus registry.
// This prometheus registry will be used to create metrics registry.
func WithPrometheusRegistry(registry *prometheus.Registry) Option {
return func(options *Builder) error {
options.prometheusRegistry = registry
return nil
}
}
// WithPrometheusListeningAddress is meant to configure cadre to use
// a separate http server for prometheus - useful for putting it behind firewall
// Default is to use the first HTTP server's listening address merging them together. This may cause problems
// when a conflicting route is configured.
func WithMetricsListeningAddress(serverListeningAddress string) Option {
return func(options *Builder) error {
options.metricsHTTPServerAddr = serverListeningAddress
return nil
}
}