Exit if specified config file is not present

This commit is contained in:
Deluan 2020-07-03 10:10:49 -04:00
parent f45045d1c0
commit 2d0539300d
1 changed files with 5 additions and 2 deletions

View File

@ -88,15 +88,18 @@ func InitConfig(cfgFile string) {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
if err := viper.ReadInConfig(); err != nil {
fmt.Println("Navidrome could not open config file: ", err)
os.Exit(1)
}
} else {
// Search config in local directory with name "navidrome" (without extension).
viper.AddConfigPath(".")
viper.SetConfigName("navidrome")
_ = viper.ReadInConfig()
}
_ = viper.BindEnv("port")
viper.SetEnvPrefix("ND")
viper.AutomaticEnv()
_ = viper.ReadInConfig()
}