initial commit
This commit is contained in:
50
config.go
Normal file
50
config.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func ReadConfig() (*viper.Viper, error) {
|
||||
defaults := map[string]any{
|
||||
"name": "COOPGO Solidarity Transport",
|
||||
"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{
|
||||
"drivers_regular_availabilities": "solidarity_drivers_regular_availabilities",
|
||||
"bookings": "solidarity_bookings",
|
||||
"driver_journeys": "solidarity_driver_journeys",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"services": map[string]any{
|
||||
"grpc": map[string]any{
|
||||
"enable": true,
|
||||
"port": 8080,
|
||||
},
|
||||
},
|
||||
"routing": map[string]any{
|
||||
"type": "valhalla",
|
||||
"base_url": "https://valhalla.coopgo.io",
|
||||
},
|
||||
}
|
||||
|
||||
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