2022-08-02 10:26:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ReadConfig() (*viper.Viper, error) {
|
2024-03-27 12:32:50 +00:00
|
|
|
// defaults := map[string]any{
|
|
|
|
// "name": "COOPGO Mobility Accounts",
|
|
|
|
// "dev_env": false,
|
|
|
|
// "storage": map[string]any{
|
|
|
|
// "db": map[string]any{
|
|
|
|
// "type": "psql",
|
|
|
|
// "psql": map[string]any{
|
|
|
|
// "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",
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// },
|
2022-08-02 10:26:28 +00:00
|
|
|
defaults := map[string]any{
|
|
|
|
"name": "COOPGO Mobility Accounts",
|
|
|
|
"dev_env": false,
|
|
|
|
"storage": map[string]any{
|
|
|
|
"db": map[string]any{
|
2024-03-27 12:32:50 +00:00
|
|
|
"type": "mongodb",
|
|
|
|
"mongodb": map[string]any{
|
|
|
|
"host": "localhost",
|
|
|
|
"port": "27017",
|
|
|
|
"db_name": "coopgo_platform",
|
|
|
|
"collections": map[string]any{
|
|
|
|
"users": "users",
|
2023-05-01 22:34:33 +00:00
|
|
|
},
|
|
|
|
},
|
2022-08-02 10:26:28 +00:00
|
|
|
},
|
|
|
|
"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
|
|
|
|
}
|