From 228862fefaa645026caa483ffe9993bf8c00b22e Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 1 Jun 2019 18:18:09 -0700 Subject: Refactor config package - Parse configuration only once during startup time - Store configuration values in a global variable --- cli/cli.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'cli/cli.go') diff --git a/cli/cli.go b/cli/cli.go index 623b9bb..ae94aba 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -51,9 +51,11 @@ func Parse() { flag.BoolVar(&flagDebugMode, "debug", false, flagDebugModeHelp) flag.Parse() - cfg := config.NewConfig() + if err := config.ParseConfig(); err != nil { + logger.Fatal("%v", err) + } - if flagDebugMode || cfg.HasDebugMode() { + if flagDebugMode || config.Opts.HasDebugMode() { logger.EnableDebug() } @@ -67,7 +69,15 @@ func Parse() { return } - db, err := database.NewConnectionPool(cfg.DatabaseURL(), cfg.DatabaseMinConns(), cfg.DatabaseMaxConns()) + if config.Opts.IsDefaultDatabaseURL() { + logger.Info("The default value for DATABASE_URL is used") + } + + db, err := database.NewConnectionPool( + config.Opts.DatabaseURL(), + config.Opts.DatabaseMinConns(), + config.Opts.DatabaseMaxConns(), + ) if err != nil { logger.Fatal("Unable to connect to the database: %v", err) } @@ -101,14 +111,14 @@ func Parse() { } // Run migrations and start the deamon. - if cfg.RunMigrations() { + if config.Opts.RunMigrations() { database.Migrate(db) } // Create admin user and start the deamon. - if cfg.CreateAdmin() { + if config.Opts.CreateAdmin() { createAdmin(store) } - startDaemon(cfg, store) + startDaemon(store) } -- cgit v1.2.3