mirror of https://github.com/mainnika/a-quest.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
651 B
39 lines
651 B
5 years ago
|
package configure
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"github.com/sirupsen/logrus"
|
||
|
"github.com/spf13/viper"
|
||
|
|
||
|
"github.com/mainnika/a-quest/task1-backend/lib"
|
||
|
"github.com/mainnika/a-quest/task1-backend/lib/env"
|
||
|
)
|
||
|
|
||
|
var Config lib.AppConfig
|
||
|
|
||
|
func init() {
|
||
|
|
||
|
path := env.ConfigPath
|
||
|
name := env.ConfigName
|
||
|
|
||
|
if len(path) == 0 {
|
||
|
path = lib.ConfPath
|
||
|
}
|
||
|
|
||
|
if len(name) == 0 {
|
||
|
name = lib.ConfName
|
||
|
}
|
||
|
|
||
|
viper.AddConfigPath(path)
|
||
|
viper.SetConfigName(name)
|
||
|
viper.SetEnvPrefix(env.Prefix)
|
||
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||
|
viper.AutomaticEnv()
|
||
|
|
||
|
err, _ := viper.ReadInConfig(), viper.Unmarshal(&Config)
|
||
|
if err != nil {
|
||
|
logrus.Fatal(err)
|
||
|
}
|
||
|
}
|