Add method to load the config
This commit is contained in:
parent
2ac0df3494
commit
d8a28fb211
@ -116,8 +116,6 @@ func Run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
var err error
|
|
||||||
|
|
||||||
C = NewConfig()
|
C = NewConfig()
|
||||||
|
|
||||||
viper.SetEnvPrefix("BEEPBOOP")
|
viper.SetEnvPrefix("BEEPBOOP")
|
||||||
@ -132,13 +130,17 @@ func initConfig() {
|
|||||||
viper.BindEnv("DISCORD_TOKEN")
|
viper.BindEnv("DISCORD_TOKEN")
|
||||||
viper.BindEnv("OPEN_WEATHER_MAP_TOKEN")
|
viper.BindEnv("OPEN_WEATHER_MAP_TOKEN")
|
||||||
|
|
||||||
|
loadConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadConfig() {
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
||||||
log.Fatalf("fatal error config file: %v", err)
|
log.Fatalf("fatal error config file: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = viper.Unmarshal(&C)
|
err := viper.Unmarshal(&C)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("unable to decode into struct: %v", err)
|
log.Fatalf("unable to decode into struct: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user