From 5d2a911b898aec16b357d58e41bb4386249362b7 Mon Sep 17 00:00:00 2001 From: akuma06 Date: Fri, 21 Jul 2017 01:20:04 +0200 Subject: [PATCH] Fix for config cli args --- config/config.go | 12 +++++++++--- main.go | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index eb1cb1a5..dc968702 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,7 @@ var ( var config *Config var once sync.Once +var configpaths = []string{DefaultConfigPath, ConfigPath} func Get() *Config { once.Do(func() { @@ -59,19 +60,24 @@ func init() { // Reload the configuration from the files provided in the config variables func Reload() { - configor.Load(Get(), DefaultConfigPath, ConfigPath) + configor.Load(Get(), configpaths...) } // BindFlags returns a function which is to be used after // flag.Parse to check and copy the flags' values to the Config instance. -func BindFlags() { +func BindFlags() func() { confFile := flag.String("conf", ConfigPath, "path to the configuration file") flag.StringVar(&Get().DBType, "dbtype", Get().DBType, "database backend") flag.StringVar(&Get().Host, "host", Get().Host, "binding address of the server") flag.IntVar(&Get().Port, "port", Get().Port, "port of the server") flag.StringVar(&Get().DBParams, "dbparams", Get().DBParams, "parameters to open the database (see Gorm's doc)") flag.StringVar(&Get().DBLogMode, "dblogmode", Get().DBLogMode, "database log verbosity (errors only by default)") - configor.Load(Get(), DefaultConfigPath, ConfigPath, *confFile) + return func() { + if *confFile != "" { + configpaths = append(configpaths, *confFile) + Reload() + } + } } // Pretty : Write config json in a file diff --git a/main.go b/main.go index 1627c0d5..b40c7758 100644 --- a/main.go +++ b/main.go @@ -66,7 +66,7 @@ func main() { conf.Build = "unknown" } defaults := flag.Bool("print-defaults", false, "print the default configuration file on stdout") - config.BindFlags() + callback := config.BindFlags() flag.Parse() if *defaults { stdout := bufio.NewWriter(os.Stdout) @@ -80,6 +80,7 @@ func main() { } os.Exit(0) } else { + callback() var err error models.ORM, err = models.GormInit(conf, models.DefaultLogger) if err != nil {