fix: change helpers to config.go and add some default configs
This commit is contained in:
parent
d7b007b851
commit
8edea3f0b8
@ -40,6 +40,22 @@ const (
|
|||||||
configType = "yaml"
|
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.
|
// initConfig reads in config file and ENV variables if set.
|
||||||
func initConfig() {
|
func initConfig() {
|
||||||
if cfgFile != "" {
|
if cfgFile != "" {
|
||||||
@ -65,7 +81,7 @@ func initConfig() {
|
|||||||
viper.SetEnvKeyReplacer(replacer)
|
viper.SetEnvKeyReplacer(replacer)
|
||||||
|
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user