multimodal-routing/config.go

42 lines
754 B
Go

package main
import (
"strings"
"github.com/spf13/viper"
)
func ReadConfig() (*viper.Viper, error) {
defaults := map[string]any{
"name": "COOPGO Multimodal Routing",
"dev_env": false,
"modes": map[string]any{
"carpool": map[string]any{
"enabled": true,
"operators": []map[string]any{},
},
},
"services": map[string]any{
"grpc": map[string]any{
"enable": true,
"port": 8080,
},
"http": map[string]any{
"enable": false,
"port": 80,
},
},
}
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
}