mobility-accounts/config.go

83 lines
1.9 KiB
Go
Raw Normal View History

package main
import (
"strings"
"github.com/spf13/viper"
)
func ReadConfig() (*viper.Viper, error) {
defaults := map[string]any{
"name": "COOPGO Mobility Accounts",
"dev_env": false,
"storage": map[string]any{
"db": map[string]any{
2023-07-18 10:38:07 +00:00
"type": "psql",
"psql": map[string]any{
2023-07-18 10:38:07 +00:00
"user": "postgres",
"password": "postgres",
"host": "localhost",
"port": "5432",
"dbname": "coopgo_platform",
"sslmode": "disable",
"schema": "mobilityaccounts",
"tables": map[string]any{
"accounts": "accounts",
"accounts_auth_local": "accounts_auth_local",
},
},
},
"kv": map[string]any{
"type": "etcd",
"etcd": map[string]any{
"endpoints": []string{"localhost:2379"},
"prefix": "mobilityaccounts/",
},
},
},
"data_schemas": map[string]map[string]string{
"personal_informations": {
"name": "(CMS) Personal informations",
"schema": "schemas/CMS/personal-information.schema.json",
},
"civil_status": {
"name": "(CMS) Civil status",
"schema": "schemas/CMS/civil-status.schema.json",
},
"favorites": {
"name": "(CMS) Favorites",
"schema": "schemas/CMS/favorites.schema.json",
},
"driving_licence": {
"name": "(CMS) Driving licence",
"schema": "schemas/CMS/driving-licence.schema.json",
},
"ice": {
"name": "(CMS) In case of emergency contacts",
"schema": "schemas/CMS/in-case-of-emergency-contacts.schema.json",
},
},
"allow_any_data": true,
"services": map[string]any{
"grpc": map[string]any{
"enable": true,
"port": 8090,
},
"oidc_provider": map[string]any{
"enable": false,
},
},
}
v := viper.New()
for key, value := range defaults {
v.SetDefault(key, value)
}
v.SetConfigName("config")
v.AddConfigPath(".")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
err := v.ReadInConfig()
return v, err
}