This repository has been archived by the owner on Sep 14, 2021. It is now read-only.
/
config.go
58 lines (48 loc) · 1.63 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
package app
import (
"crypto/tls"
"io"
"io/ioutil"
"log"
"os"
"time"
envstruct "code.cloudfoundry.org/go-envstruct"
)
// Config stores configuration data for the noisy neighbor client.
type Config struct {
UAAAddr string `env:"UAA_ADDR, required"`
ClientID string `env:"CLIENT_ID, required"`
ClientSecret string `env:"CLIENT_SECRET, required, noreport"`
LoggregatorAddr string `env:"LOGGREGATOR_ADDR, required"`
Port uint16 `env:"PORT, required"`
SubscriptionID string `env:"SUBSCRIPTION_ID, required"`
SkipCertVerify bool `env:"SKIP_CERT_VERIFY"`
BufferSize int `env:"BUFFER_SIZE"`
PollingInterval time.Duration `env:"POLLING_INTERVAL"`
MaxRateBuckets int `env:"MAX_RATE_BUCKETS"`
IncludeRouterLogs bool `env:"INCLUDE_ROUTER_LOGS"`
// VCapApplication is used to detect whether or not the application is
// deployed as a CF application.
VCapApplication string `env:"VCAP_APPLICATION"`
TLSConfig *tls.Config
LogWriter io.Writer
}
// LoadConfig loads the Config from the environment
func LoadConfig() Config {
cfg := Config{
SkipCertVerify: false,
BufferSize: 10000,
PollingInterval: time.Minute,
MaxRateBuckets: 60,
IncludeRouterLogs: false,
LogWriter: os.Stdout,
}
if err := envstruct.Load(&cfg); err != nil {
log.Fatalf("failed to load config from environment: %s", err)
}
if cfg.VCapApplication != "" {
cfg.LogWriter = ioutil.Discard
}
cfg.TLSConfig = &tls.Config{InsecureSkipVerify: cfg.SkipCertVerify}
return cfg
}