silvermobi/services/services.go

55 lines
1.7 KiB
Go
Raw Normal View History

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"
routing "git.coopgo.io/coopgo-platform/routing-service"
2023-08-08 10:28:43 +00:00
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)
type ServicesHandler struct {
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
}
func NewServicesHandler(cfg *viper.Viper) (*ServicesHandler, error) {
var (
mobilityAccountsDial = cfg.GetString("services.internal.mobility_accounts.dial")
pushDial = cfg.GetString("services.internal.push.dial")
2023-12-08 06:35:04 +00:00
geocoder_type = cfg.GetString("geocoder.type")
pelias_base_url = cfg.GetString("geocoder.pelias.base_url")
routing_service_type = cfg.GetString("routing.type")
valhalla_base_url = cfg.GetString("routing.valhalla.base_url")
2023-08-08 10:28:43 +00:00
)
mobilityAccounts, err := NewMobilityAccountService(mobilityAccountsDial)
if err != nil {
log.Fatal().Err(err).Msg("Could not connect to Mobility Accounts Service")
return nil, err
}
push, err := NewPushService(pushDial)
if err != nil {
log.Fatal().Err(err).Msg("Could not connect to Push Notifications Service")
return nil, err
}
2023-12-08 06:35:04 +00:00
geocoder, err := geocode.NewGeocoder(geocoder_type, pelias_base_url)
if err != nil {
log.Fatal().Err(err).Msg("Could not initiate the Geocoder service")
return nil, err
}
routing, err := routing.NewRoutingService(routing_service_type, valhalla_base_url)
if err != nil {
log.Fatal().Err(err).Msg("Could not initiate the routing service")
return nil, err
}
2023-08-08 10:28:43 +00:00
return &ServicesHandler{
MobilityAccounts: mobilityAccounts,
Push: push,
2023-12-08 06:35:04 +00:00
Geocoder: geocoder,
Routing: routing,
2023-08-08 10:28:43 +00:00
}, nil
}