From b419cfde698c987bb633c9e727d245f5ecddff07 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Thu, 8 Sep 2022 00:59:10 -0500 Subject: [PATCH] Fix workaround for optional config file with Viper There was a false error reported when the configuration file was found --- bot/bot.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/bot.go b/bot/bot.go index 6d5810c..7b6bf94 100644 --- a/bot/bot.go +++ b/bot/bot.go @@ -126,14 +126,14 @@ func setupConfig() { viper.SetConfigType("toml") viper.AddConfigPath(".") - err = viper.ReadInConfig() - viper.BindEnv("DEBUG") viper.BindEnv("DISCORD_TOKEN") viper.BindEnv("OPEN_WEATHER_MAP_TOKEN") - if _, ok := err.(viper.ConfigFileNotFoundError); !ok { - log.Fatalf("fatal error config file: %v", err) + if err := viper.ReadInConfig(); err != nil { + if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + log.Fatalf("fatal error config file: %v", err) + } } err = viper.Unmarshal(&C)