fix(config): ensure provided config path is used (#508)
Former-commit-id: 519c027039de94232d801df4a71187096888f6bd [formerly f76f9459eeb7d8038b8d9b31af2e562c2984809e] [formerly 6b532750f58cf0eabaffacb772b623a9ecbf8e5b [formerly 1e12bb7f7cc271aeb3582e50e1c9355a2c9f51af]] Former-commit-id: 17a85007590f31c7ef1c2e6d125d30191eaa4d7d [formerly 4ee6dc582cc4e1c086f55901902864d784d392d5] Former-commit-id: 9daf15d9a1131f8f45ce35a9b676dfdc8cd4b099
This commit is contained in:
parent
6b4bce5daf
commit
e471e79d50
|
@ -117,9 +117,6 @@ func setupViper() {
|
||||||
viper.BindPFlag("AlternativeRecaptcha", flag.Lookup("alternative-recaptcha"))
|
viper.BindPFlag("AlternativeRecaptcha", flag.Lookup("alternative-recaptcha"))
|
||||||
viper.BindPFlag("ReCaptchaKey", flag.Lookup("recaptcha-key"))
|
viper.BindPFlag("ReCaptchaKey", flag.Lookup("recaptcha-key"))
|
||||||
viper.BindPFlag("ReCaptchaSecret", flag.Lookup("recaptcha-secret"))
|
viper.BindPFlag("ReCaptchaSecret", flag.Lookup("recaptcha-secret"))
|
||||||
|
|
||||||
viper.SetConfigName("filebrowser")
|
|
||||||
viper.AddConfigPath(".")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func printVersion() {
|
func printVersion() {
|
||||||
|
@ -127,6 +124,29 @@ func printVersion() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initConfig() {
|
||||||
|
// Add a configuration file if set.
|
||||||
|
if config != "" {
|
||||||
|
cfg := strings.TrimSuffix(config, filepath.Ext(config))
|
||||||
|
if dir := filepath.Dir(cfg); dir != "" {
|
||||||
|
viper.AddConfigPath(dir)
|
||||||
|
cfg = strings.TrimPrefix(cfg, dir)
|
||||||
|
}
|
||||||
|
viper.SetConfigName(cfg)
|
||||||
|
} else {
|
||||||
|
viper.SetConfigName("filebrowser")
|
||||||
|
viper.AddConfigPath(".")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read configuration from a file if exists.
|
||||||
|
err := viper.ReadInConfig()
|
||||||
|
if err != nil {
|
||||||
|
if _, ok := err.(viper.ConfigParseError); ok {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
setupViper()
|
setupViper()
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -135,27 +155,7 @@ func main() {
|
||||||
printVersion()
|
printVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a configuration file if set.
|
initConfig();
|
||||||
if config != "" {
|
|
||||||
ext := filepath.Ext(config)
|
|
||||||
dir := filepath.Dir(config)
|
|
||||||
config = strings.TrimSuffix(config, ext)
|
|
||||||
|
|
||||||
if dir != "" {
|
|
||||||
viper.AddConfigPath(dir)
|
|
||||||
config = strings.TrimPrefix(config, dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
viper.SetConfigName(config)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read configuration from a file if exists.
|
|
||||||
err := viper.ReadInConfig()
|
|
||||||
if err != nil {
|
|
||||||
if _, ok := err.(viper.ConfigParseError); ok {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up process log before anything bad happens.
|
// Set up process log before anything bad happens.
|
||||||
switch viper.GetString("Logger") {
|
switch viper.GetString("Logger") {
|
||||||
|
|
Loading…
Reference in New Issue