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 }