mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03:00
config: don't log a warning if the config file is not found
we also support configuration via env vars
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -369,8 +370,16 @@ func LoadConfig(configDir, configFile string) error {
|
|||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
setConfigFile(configDir, configFile)
|
setConfigFile(configDir, configFile)
|
||||||
if err = viper.ReadInConfig(); err != nil {
|
if err = viper.ReadInConfig(); err != nil {
|
||||||
logger.Warn(logSender, "", "error loading configuration file: %v", err)
|
// if the user specify a configuration file we get os.ErrNotExist.
|
||||||
logger.WarnToConsole("error loading configuration file: %v", err)
|
// viper.ConfigFileNotFoundError is returned if viper is unable
|
||||||
|
// to find sftpgo.{json,yaml, etc..} in any of the search paths
|
||||||
|
if errors.As(err, &viper.ConfigFileNotFoundError{}) {
|
||||||
|
logger.Debug(logSender, "", "no configuration file found")
|
||||||
|
} else {
|
||||||
|
// should we return the error and not start here?
|
||||||
|
logger.Warn(logSender, "", "error loading configuration file: %v", err)
|
||||||
|
logger.WarnToConsole("error loading configuration file: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
err = viper.Unmarshal(&globalConf)
|
err = viper.Unmarshal(&globalConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -58,6 +58,14 @@ func TestLoadConfigTest(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadConfigFileNotFound(t *testing.T) {
|
||||||
|
reset()
|
||||||
|
|
||||||
|
viper.SetConfigName("configfile")
|
||||||
|
err := config.LoadConfig(os.TempDir(), "")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestEmptyBanner(t *testing.T) {
|
func TestEmptyBanner(t *testing.T) {
|
||||||
reset()
|
reset()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user