groups-management/config.go

46 lines
885 B
Go
Raw Normal View History

2022-08-11 15:21:32 +00:00
package main
import (
"strings"
"github.com/spf13/viper"
)
func ReadConfig() (*viper.Viper, error) {
defaults := map[string]any{
"name": "COOPGO Groups Management",
"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{
"groups": "groups",
"groups_member": "groups_member",
2022-08-11 15:21:32 +00:00
},
},
},
},
"services": map[string]any{
"grpc": map[string]any{
"enable": true,
"port": 8092,
},
},
}
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
}