From d8a28fb211e1bbbaced8b1eb5079d25819e1f13f Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Thu, 8 Sep 2022 02:26:47 -0500 Subject: [PATCH] Add method to load the config --- bot/bot.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bot/bot.go b/bot/bot.go index 3416b41..35b8eb5 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -116,8 +116,6 @@ func Run() error { } func initConfig() { - var err error - C = NewConfig() viper.SetEnvPrefix("BEEPBOOP") @@ -132,13 +130,17 @@ func initConfig() { viper.BindEnv("DISCORD_TOKEN") viper.BindEnv("OPEN_WEATHER_MAP_TOKEN") + loadConfig() +} + +func loadConfig() { if err := viper.ReadInConfig(); err != nil { if _, ok := err.(viper.ConfigFileNotFoundError); !ok { log.Fatalf("fatal error config file: %v", err) } } - err = viper.Unmarshal(&C) + err := viper.Unmarshal(&C) if err != nil { log.Fatalf("unable to decode into struct: %v", err) }