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{ // "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", // }, // }, // }, defaults := map[string]any{ "name": "COOPGO Mobility Accounts", "dev_env": false, "storage": map[string]any{ "db": map[string]any{ "type": "mongodb", "mongodb": map[string]any{ "host": "localhost", "port": "27017", "db_name": "coopgo_platform", "collections": map[string]any{ "users": "users", }, }, }, "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 }