carpool-incentives/config.go

60 lines
1.3 KiB
Go
Raw Permalink Normal View History

2023-03-12 23:23:59 +00:00
package main
import (
"strings"
"github.com/spf13/viper"
)
func ReadConfig() (*viper.Viper, error) {
2023-05-07 23:16:08 +00:00
defaults := map[string]any{
"name": "COOPGO Carpool Incentives",
"dev_env": false,
"storage": map[string]any{
"db": map[string]any{
"type": "psql",
"mongodb": map[string]any{
"host": "localhost",
"port": 27017,
"db_name": "coopgo_platform",
"collections": map[string]string{
"incentive_subscriptions": "carpool_incentive_subscriptions",
"proofs": "carpool_proofs",
},
},
"psql": map[string]any{
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "postgres",
"dbname": "coopgo_platform",
"schema": "carpool_incentives",
"sslmode": "disable",
"tables": map[string]string{
"incentive_subscriptions": "incentive_subscriptions",
"proofs": "proofs",
},
},
},
},
"services": map[string]any{
"grpc": map[string]any{
"enable": true,
"port": 8080,
},
},
}
2023-03-12 23:23:59 +00:00
v := viper.New()
2023-05-07 23:16:08 +00:00
for key, value := range defaults {
v.SetDefault(key, value)
}
2023-03-12 23:23:59 +00:00
v.SetConfigName("config")
v.AddConfigPath(".")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
err := v.ReadInConfig()
return v, err
}