-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
36 lines (29 loc) · 899 Bytes
/
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
package main
import (
"net/url"
"github.com/kelseyhightower/envconfig"
"github.com/rs/zerolog/log"
)
type Config struct {
LogLevel string `envconfig:"LOG_LEVEL" default:"info"`
LogPretty bool `envconfig:"LOG_PRETTY" default:"false"`
Port int `envconfig:"PORT" default:"8000"`
QueriesFile string `envconfig:"QUERIES" default:"queries.yaml"`
Prometheus url.URL `envconfig:"PROMETHEUS" required:"true"`
}
func MustParseConfig() Config {
var c Config
err := envconfig.Process("", &c)
if err != nil {
_ = envconfig.Usage("", &c)
log.Fatal().Msg(err.Error())
}
initLogger(c)
log.Info().Msg("Starting")
log.Info().Int("Port", c.Port).Send()
log.Info().Str("Log level", c.LogLevel).Send()
log.Info().Bool("Log pretty", c.LogPretty).Send()
log.Info().Stringer("Prometheus", &c.Prometheus).Send()
log.Info().Str("Queries file", c.QueriesFile).Send()
return c
}