-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
54 lines (44 loc) · 1.06 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
package lumigotracer
import (
"github.com/spf13/viper"
)
// Config describes the struct about the configuration
// of the wrap handler for tracer
type Config struct {
// enabled switch off SDK completely
enabled bool
// Token is used to interact with Lumigo API
Token string
// debug log everything
debug bool
// PrintStdout prints in stdout
PrintStdout bool
}
// cfg it's a public empty config
var cfg Config
// validate runs a validation to the required fields
// for this Config struct
func (cfg Config) validate() error { // nolint
if cfg.Token == "" {
return ErrInvalidToken
}
return nil
}
// init not really used right now
func init() {
viper.AutomaticEnv()
viper.SetEnvPrefix("LUMIGO")
viper.SetDefault("ENABLED", true)
viper.SetDefault("DEBUG", false)
}
func loadConfig(conf Config) error {
defer recoverWithLogs()
cfg.Token = viper.GetString("TRACER_TOKEN")
if cfg.Token == "" {
cfg.Token = conf.Token
}
cfg.enabled = viper.GetBool("ENABLED")
cfg.debug = viper.GetBool("DEBUG")
cfg.PrintStdout = conf.PrintStdout
return cfg.validate()
}