-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
38 lines (32 loc) · 898 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
37
38
package main
import (
"github.com/spf13/viper"
"time"
)
type Config struct {
HdgEndpoint string `mapstructure:"HDG_ENDPOINT"`
Language string `mapstructure:"HDG_LANGUAGE"`
Ids []int `mapstructure:"HDG_IDS"`
Timeout time.Duration `mapstructure:"HDG_TIMEOUT"`
Port int `mapstructure:"PORT"`
}
func loadConfig() (config Config, err error) {
viper.AddConfigPath(".")
viper.SetConfigName("app")
viper.SetConfigType("env")
viper.AutomaticEnv()
viper.SetDefault("HDG_LANGUAGE", "deutsch")
viper.SetDefault("HDG_TIMEOUT", "30s")
viper.SetDefault("PORT", 8080)
err = viper.ReadInConfig()
if err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// Config file not found; ignore error
} else {
// Config file was found but another error was produced
return
}
}
err = viper.Unmarshal(&config)
return
}