config: add configDir before additional search paths

This way the configuration will be searched in the following order:

- config dir
- $HOME/.config/sftpgo
- /etc/sftpgo
- current directory
This commit is contained in:
Nicola Murino 2019-09-05 22:07:59 +02:00
parent 795ffc4c5f
commit 53d70b68d8

View file

@ -83,8 +83,6 @@ func init() {
replacer := strings.NewReplacer(".", "__")
viper.SetEnvKeyReplacer(replacer)
viper.SetConfigName(DefaultConfigName)
setViperAdditionalConfigPaths()
viper.AddConfigPath(".")
viper.AutomaticEnv()
viper.AllowEmptyEnv(true)
}
@ -112,6 +110,8 @@ func GetProviderConf() dataprovider.Config {
func LoadConfig(configDir, configName string) error {
var err error
viper.AddConfigPath(configDir)
setViperAdditionalConfigPaths()
viper.AddConfigPath(".")
viper.SetConfigName(configName)
if err = viper.ReadInConfig(); err != nil {
logger.Warn(logSender, "error loading configuration file: %v. Default configuration will be used: %+v", err, globalConf)