Add method to load the config

This commit is contained in:
Ryan Cavicchioni 2022-09-08 02:26:47 -05:00
parent 2ac0df3494
commit d8a28fb211
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D

View File

@ -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)
} }