package services import ( "git.coopgo.io/coopgo-platform/geocode" "git.coopgo.io/coopgo-platform/routing-service" "github.com/rs/zerolog/log" "github.com/spf13/viper" ) type ServiceHandler struct { MobilityAccounts MobilityAccountService Push *PushService Geocoder geocode.Geocoder Routing routing.RoutingService } func NewServicesHandler(cfg *viper.Viper) (*ServiceHandler, error) { var ( mobilityAccountsDial = cfg.GetString("services.internal.mobility_accounts.dial") pushDial = cfg.GetString("services.internal.push.dial") geocoderType = cfg.GetString("geocoder.type") peliasBaseUrl = cfg.GetString("geocoder.pelias.base_url") routingServiceType = cfg.GetString("routing.type") valhallaBaseUrl = cfg.GetString("routing.valhalla.base_url") mobilityAccounts MobilityAccountService push *PushService geocoder geocode.Geocoder routingsvc routing.RoutingService err error ) if mobilityAccounts, err = NewMobilityAccountService(mobilityAccountsDial); err != nil { log.Fatal().Err(err).Msg("Could not connect to Mobility Accounts Service") return nil, err } if push, err = NewPushService(pushDial); err != nil { log.Fatal().Err(err).Msg("Could not connect to Push Notifications Service") return nil, err } if geocoder, err = geocode.NewGeocoder(geocoderType, peliasBaseUrl); err != nil { log.Fatal().Err(err).Msg("Could not initiate the Geocoder service") return nil, err } if routingsvc, err = routing.NewRoutingService(routingServiceType, valhallaBaseUrl); err != nil { log.Fatal().Err(err).Msg("Could not initiate the routing service") return nil, err } return &ServiceHandler{ MobilityAccounts: mobilityAccounts, Push: push, Geocoder: geocoder, Routing: routingsvc, }, nil }