-
Notifications
You must be signed in to change notification settings - Fork 7
/
options.go
72 lines (63 loc) · 2.25 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
package push
import "time"
// An Option represents a configuration option
// for the Upstreamer.
type Option func(*upstreamConfig)
type upstreamConfig struct {
overrideEndpointAddress string
exposePrivateAPIs bool
eventsAPIs map[string]string
requiredServices []string
serviceTimeout time.Duration
serviceTimeoutCheckInterval time.Duration
}
func newUpstreamConfig() upstreamConfig {
return upstreamConfig{
eventsAPIs: map[string]string{},
serviceTimeout: 30 * time.Second,
serviceTimeoutCheckInterval: 5 * time.Second,
}
}
// OptionExposePrivateAPIs configures the Upstreamer to expose
// the private APIs.
func OptionExposePrivateAPIs(enabled bool) Option {
return func(cfg *upstreamConfig) {
cfg.exposePrivateAPIs = enabled
}
}
// OptionOverrideEndpointsAddresses configures the Upstreamer
// to always ignore what IP address the services are reporting
// and always use the provided address.
func OptionOverrideEndpointsAddresses(override string) Option {
return func(cfg *upstreamConfig) {
cfg.overrideEndpointAddress = override
}
}
// OptionRegisterEventAPI registers an event API for the given serviceName
// on the given endpoint.
// For instance is serviceA exposes an event API on /events, you can use
//
// OptionRegisterEventAPI("serviceA", "events")
func OptionRegisterEventAPI(serviceName string, eventEndpoint string) Option {
return func(cfg *upstreamConfig) {
cfg.eventsAPIs[serviceName] = eventEndpoint
}
}
// OptionRequiredServices sets the list of services
// that must be ready before starting the upstreamer.
func OptionRequiredServices(required []string) Option {
return func(cfg *upstreamConfig) {
cfg.requiredServices = required
}
}
// OptionServiceTimeout sets the time to wait for the upstream
// to consider a service that did not ping to be outdated and removed
// in the case no goodbye was sent. Default is 30s.
// The check interval parameters defines how often the upstream
// will check for outdated services. The default is 5s.
func OptionServiceTimeout(timeout time.Duration, checkInterval time.Duration) Option {
return func(cfg *upstreamConfig) {
cfg.serviceTimeout = timeout
cfg.serviceTimeoutCheckInterval = checkInterval
}
}