From f5ebada91351faf1e5602f0260908defaaabd810 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 23 May 2022 22:12:15 +0200 Subject: [PATCH] fix: set derived default values only after reading config from file or env --- pkg/config/config.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 894dbd884..dfde771ef 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -392,6 +392,18 @@ func InitConfig() { viper.AddConfigPath(".") viper.SetConfigName("config") + err = viper.ReadInConfig() + if viper.ConfigFileUsed() != "" { + log.Printf("Using config file: %s", viper.ConfigFileUsed()) + + if err != nil { + log.Println(err.Error()) + log.Println("Using default config.") + } + } else { + log.Println("No config file found, using default or config from environment variables.") + } + if CacheType.GetString() == "keyvalue" { CacheType.Set(KeyvalueType.GetString()) } @@ -424,19 +436,6 @@ func InitConfig() { log.Println("WARNING: service.enablemetrics is deprecated and will be removed in a future release. Please use metrics.enable.") MetricsEnabled.Set(true) } - - err = viper.ReadInConfig() - if viper.ConfigFileUsed() != "" { - log.Printf("Using config file: %s", viper.ConfigFileUsed()) - - if err != nil { - log.Println(err.Error()) - log.Println("Using default config.") - return - } - } else { - log.Println("No config file found, using default or config from environment variables.") - } } func random(length int) (string, error) {