fix: log environment variable configuration loading when no config file is found
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -344,6 +344,8 @@ func Load(noConfigDump bool) {
|
|||||||
// Log configuration source
|
// Log configuration source
|
||||||
if Server.ConfigFile != "" {
|
if Server.ConfigFile != "" {
|
||||||
log.Info("Loaded configuration", "file", Server.ConfigFile)
|
log.Info("Loaded configuration", "file", Server.ConfigFile)
|
||||||
|
} else if hasNDEnvVars() {
|
||||||
|
log.Info("No configuration file found. Loaded configuration only from environment variables")
|
||||||
} else {
|
} else {
|
||||||
log.Warn("No configuration file found. Using default values. To specify a config file, use the --configfile flag or set the ND_CONFIGFILE environment variable.")
|
log.Warn("No configuration file found. Using default values. To specify a config file, use the --configfile flag or set the ND_CONFIGFILE environment variable.")
|
||||||
}
|
}
|
||||||
@@ -502,6 +504,16 @@ func AddHook(hook func()) {
|
|||||||
hooks = append(hooks, hook)
|
hooks = append(hooks, hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hasNDEnvVars checks if any ND_ prefixed environment variables are set (excluding ND_CONFIGFILE)
|
||||||
|
func hasNDEnvVars() bool {
|
||||||
|
for _, env := range os.Environ() {
|
||||||
|
if strings.HasPrefix(env, "ND_") && !strings.HasPrefix(env, "ND_CONFIGFILE=") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func setViperDefaults() {
|
func setViperDefaults() {
|
||||||
viper.SetDefault("musicfolder", filepath.Join(".", "music"))
|
viper.SetDefault("musicfolder", filepath.Join(".", "music"))
|
||||||
viper.SetDefault("cachefolder", "")
|
viper.SetDefault("cachefolder", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user