-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
51 lines (39 loc) · 935 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
39
40
41
42
43
44
45
46
47
48
49
50
51
package env
import (
"github.com/MinterTeam/minter-explorer-tools/helpers"
"strings"
"github.com/spf13/viper"
)
type Config interface {
GetString(key string) string
GetInt(key string) int
GetBool(key string) bool
Init()
}
type viperConfig struct {
}
func (v *viperConfig) Init() {
viper.AutomaticEnv()
viper.AddConfigPath(".")
viper.AddConfigPath("/etc/minter/") // path to look for the config file in
replacer := strings.NewReplacer(`.`, `_`)
viper.SetEnvKeyReplacer(replacer)
viper.SetConfigType(`json`)
viper.SetConfigFile(`config.json`)
err := viper.ReadInConfig()
helpers.HandleError(err)
}
func (v *viperConfig) GetString(key string) string {
return viper.GetString(key)
}
func (v *viperConfig) GetInt(key string) int {
return viper.GetInt(key)
}
func (v *viperConfig) GetBool(key string) bool {
return viper.GetBool(key)
}
func NewViperConfig() Config {
v := &viperConfig{}
v.Init()
return v
}