-
Notifications
You must be signed in to change notification settings - Fork 148
/
config.go
71 lines (57 loc) · 1.88 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package app
import (
"errors"
"code.cloudfoundry.org/go-envstruct"
)
// Agent stores the configuration for connecting to the Agent over gRPC.
type Agent struct {
GRPCAddress string `env:"AGENT_GRPC_ADDRESS"`
}
// GRPC stores the configuration for the router as a server using a PORT
// with mTLS certs and as a client also using mTSL certs for emitting metrics.
type GRPC struct {
Port uint16 `env:"ROUTER_PORT"`
CertFile string `env:"ROUTER_CERT_FILE"`
KeyFile string `env:"ROUTER_KEY_FILE"`
CAFile string `env:"ROUTER_CA_FILE"`
CipherSuites []string `env:"ROUTER_CIPHER_SUITES"`
}
// Config stores all configurations options for the Router.
type Config struct {
GRPC GRPC
IngressBufferSize int `env:"INGRESS_BUFFER_SIZE"`
EgressBufferSize int `env:"EGRESS_BUFFER_SIZE"`
UseRFC339 bool `env:"USE_RFC339"`
PProfPort uint32 `env:"ROUTER_PPROF_PORT"`
Agent Agent
MetricBatchIntervalMilliseconds uint `env:"ROUTER_METRIC_BATCH_INTERVAL_MILLISECONDS"`
MetricSourceID string `env:"ROUTER_METRIC_SOURCE_ID"`
}
// LoadConfig reads from the environment to create a Config.
func LoadConfig() (*Config, error) {
config := Config{
MetricBatchIntervalMilliseconds: 5000,
MetricSourceID: "doppler",
}
err := envstruct.Load(&config)
if err != nil {
return nil, err
}
err = config.validate()
if err != nil {
return nil, err
}
return &config, nil
}
func (c *Config) validate() (err error) {
if len(c.GRPC.CAFile) == 0 {
return errors.New("invalid router config, no GRPC.CAFile provided")
}
if len(c.GRPC.CertFile) == 0 {
return errors.New("invalid router config, no GRPC.CertFile provided")
}
if len(c.GRPC.KeyFile) == 0 {
return errors.New("invalid router config, no GRPC.KeyFile provided")
}
return nil
}