package main import ( "strings" "github.com/spf13/viper" ) func ReadConfig() (*viper.Viper, error) { defaults := map[string]any{ "name": "COOPGO Geography", "dev_env": false, "storage": map[string]any{ "index": map[string]any{ "type": "memory_rtree", "bleve": map[string]any{ "file": "index.bleve", }, }, }, "services": map[string]any{ "grpc": map[string]any{ "enable": true, "port": 8080, }, }, "data": map[string]any{ "layers": map[string]string{ "regions": "https://etalab-datasets.geo.data.gouv.fr/contours-administratifs/latest/geojson/regions-50m.geojson", "departements": "https://etalab-datasets.geo.data.gouv.fr/contours-administratifs/latest/geojson/departements-50m.geojson", "epci": "https://etalab-datasets.geo.data.gouv.fr/contours-administratifs/latest/geojson/epci-50m.geojson", "communes": "https://etalab-datasets.geo.data.gouv.fr/contours-administratifs/latest/geojson/communes-50m.geojson", }, }, } 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 }