2023-08-08 10:28:43 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2023-12-08 06:35:04 +00:00
|
|
|
"git.coopgo.io/coopgo-platform/geocode"
|
2024-11-01 00:23:34 +00:00
|
|
|
"git.coopgo.io/coopgo-platform/routing-service"
|
2023-08-08 10:28:43 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2024-10-31 19:32:54 +00:00
|
|
|
type ServiceHandler struct {
|
2023-08-08 10:28:43 +00:00
|
|
|
MobilityAccounts MobilityAccountService
|
|
|
|
Push *PushService
|
2023-12-08 06:35:04 +00:00
|
|
|
Geocoder geocode.Geocoder
|
|
|
|
Routing routing.RoutingService
|
2023-08-08 10:28:43 +00:00
|
|
|
}
|
|
|
|
|
2024-10-31 19:32:54 +00:00
|
|
|
func NewServicesHandler(cfg *viper.Viper) (*ServiceHandler, error) {
|
2023-08-08 10:28:43 +00:00
|
|
|
var (
|
|
|
|
mobilityAccountsDial = cfg.GetString("services.internal.mobility_accounts.dial")
|
|
|
|
pushDial = cfg.GetString("services.internal.push.dial")
|
2024-10-31 19:32:54 +00:00
|
|
|
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
|
2023-08-08 10:28:43 +00:00
|
|
|
)
|
2024-10-31 19:32:54 +00:00
|
|
|
|
|
|
|
if mobilityAccounts, err = NewMobilityAccountService(mobilityAccountsDial); err != nil {
|
2023-08-08 10:28:43 +00:00
|
|
|
log.Fatal().Err(err).Msg("Could not connect to Mobility Accounts Service")
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-10-31 19:32:54 +00:00
|
|
|
|
|
|
|
if push, err = NewPushService(pushDial); err != nil {
|
2023-08-08 10:28:43 +00:00
|
|
|
log.Fatal().Err(err).Msg("Could not connect to Push Notifications Service")
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-10-31 19:32:54 +00:00
|
|
|
|
|
|
|
if geocoder, err = geocode.NewGeocoder(geocoderType, peliasBaseUrl); err != nil {
|
2023-12-08 06:35:04 +00:00
|
|
|
log.Fatal().Err(err).Msg("Could not initiate the Geocoder service")
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-10-31 19:32:54 +00:00
|
|
|
if routingsvc, err = routing.NewRoutingService(routingServiceType, valhallaBaseUrl); err != nil {
|
2023-12-08 06:35:04 +00:00
|
|
|
log.Fatal().Err(err).Msg("Could not initiate the routing service")
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-08-08 10:28:43 +00:00
|
|
|
|
2024-10-31 19:32:54 +00:00
|
|
|
return &ServiceHandler{
|
2023-08-08 10:28:43 +00:00
|
|
|
MobilityAccounts: mobilityAccounts,
|
|
|
|
Push: push,
|
2024-10-31 19:32:54 +00:00
|
|
|
Geocoder: geocoder,
|
|
|
|
Routing: routingsvc,
|
2023-08-08 10:28:43 +00:00
|
|
|
}, nil
|
|
|
|
}
|