fix(config): ensure provided config path is used
@@ -117,9 +117,6 @@ func setupViper() {
viper.BindPFlag("AlternativeRecaptcha", flag.Lookup("alternative-recaptcha"))
viper.BindPFlag("ReCaptchaKey", flag.Lookup("recaptcha-key"))
viper.BindPFlag("ReCaptchaSecret", flag.Lookup("recaptcha-secret"))
-
- viper.SetConfigName("filebrowser")
- viper.AddConfigPath(".")
}
func printVersion() {
@@ -127,26 +124,18 @@ func printVersion() {
os.Exit(0)
}
-func main() {
- setupViper()
- flag.Parse()
-
- if showVer {
- printVersion()
- }
-
+func initConfig() {
// Add a configuration file if set.
if config != "" {
- ext := filepath.Ext(config)
- dir := filepath.Dir(config)
- config = strings.TrimSuffix(config, ext)
-
- if dir != "" {
+ cfg := strings.TrimSuffix(config, filepath.Ext(config))
+ if dir := filepath.Dir(cfg); dir != "" {
viper.AddConfigPath(dir)
- config = strings.TrimPrefix(config, dir)
+ cfg = strings.TrimPrefix(cfg, dir)
}
-
- viper.SetConfigName(config)
+ viper.SetConfigName(cfg)
+ } else {
+ viper.SetConfigName("filebrowser")
+ viper.AddConfigPath(".")
}
// Read configuration from a file if exists.
@@ -156,6 +145,17 @@ func main() {
panic(err)
}
}
+}
+
+func main() {
+ setupViper()
+ flag.Parse()
+
+ if showVer {
+ printVersion()
+ }
+
+ initConfig();
// Set up process log before anything bad happens.
switch viper.GetString("Logger") {
