1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

Refactor config package

- Parse configuration only once during startup time
- Store configuration values in a global variable
This commit is contained in:
Frédéric Guillot 2019-06-01 18:18:09 -07:00 committed by fguillot
parent 04d85b3c63
commit 228862fefa
28 changed files with 922 additions and 624 deletions

View file

@ -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)
}