initial commit
This commit is contained in:
41
config.go
Normal file
41
config.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user