From 8edea3f0b89815694a2836a5f0aea2cfd3f66fc5 Mon Sep 17 00:00:00 2001 From: Muyao CHEN Date: Sat, 5 Oct 2024 23:22:19 +0200 Subject: [PATCH] fix: change helpers to config.go and add some default configs --- internal/howmuch/{helpers.go => config.go} | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) rename internal/howmuch/{helpers.go => config.go} (84%) diff --git a/internal/howmuch/helpers.go b/internal/howmuch/config.go similarity index 84% rename from internal/howmuch/helpers.go rename to internal/howmuch/config.go index 73d7b16..3f7ad48 100644 --- a/internal/howmuch/helpers.go +++ b/internal/howmuch/config.go @@ -40,6 +40,22 @@ const ( configType = "yaml" ) +func defaultConfig() { + viper.SetDefault("dev-mode", true) + + // web + viper.SetDefault("web.addr", ":8000") + viper.SetDefault("web.shutdown-timeout", "10") + + // db + viper.SetDefault("db.host", "localhost") + viper.SetDefault("db.port", 5432) + viper.SetDefault("db.username", "howmuch") + viper.SetDefault("db.password", "howmuch") + viper.SetDefault("db.database", "howmuch") + viper.SetDefault("db.sslmode", "disable") +} + // initConfig reads in config file and ENV variables if set. func initConfig() { if cfgFile != "" { @@ -65,7 +81,7 @@ func initConfig() { viper.SetEnvKeyReplacer(replacer) if err := viper.ReadInConfig(); err != nil { - log.ErrorLog("Failed to read viper configuration file", "err", err) + log.ErrorLog("Failed to read viper configuration file, use default config", "err", err) return }