fix: change helpers to config.go and add some default configs

This commit is contained in:
Muyao CHEN 2024-10-05 23:22:19 +02:00
parent d7b007b851
commit 8edea3f0b8

View File

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