fix: set derived default values only after reading config from file or env

This commit is contained in:
kolaente 2022-05-23 22:12:15 +02:00
parent 7b10176a10
commit f5ebada913
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B

View file

@ -392,6 +392,18 @@ func InitConfig() {
viper.AddConfigPath(".") viper.AddConfigPath(".")
viper.SetConfigName("config") 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" { if CacheType.GetString() == "keyvalue" {
CacheType.Set(KeyvalueType.GetString()) 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.") log.Println("WARNING: service.enablemetrics is deprecated and will be removed in a future release. Please use metrics.enable.")
MetricsEnabled.Set(true) 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) { func random(length int) (string, error) {