parcoursmob/services/services.go

79 lines
2.3 KiB
Go
Raw Normal View History

package services
import (
2022-09-05 05:25:05 +00:00
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
2024-08-07 13:01:01 +00:00
routing "git.coopgo.io/coopgo-platform/routing-service"
solidarityservice "git.coopgo.io/sbouaram/solidarity-service/servers/grpc/proto"
"github.com/spf13/viper"
2024-08-07 13:01:01 +00:00
"github.com/rs/zerolog/log"
)
type ServicesHandler struct {
GRPC GRPCServices
}
type GRPCServices struct {
MobilityAccounts mobilityaccounts.MobilityAccountsClient
GroupsManagement groupsmanagement.GroupsManagementClient
Fleets fleets.FleetsClient
Agenda agenda.AgendaClient
2024-08-07 13:01:01 +00:00
SolidarityService solidarityservice.SolidarityServiceClient
Routing routing.RoutingService
}
func NewServicesHandler(cfg *viper.Viper) (*ServicesHandler, error) {
var (
mobilityAccountsDial = cfg.GetString("services.grpc.mobilityaccounts.dial")
groupsManagementDial = cfg.GetString("services.grpc.groupsmanagement.dial")
fleetsDial = cfg.GetString("services.grpc.fleets.dial")
2022-09-05 05:25:05 +00:00
agendaDial = cfg.GetString("services.grpc.agenda.dial")
2024-08-07 13:01:01 +00:00
solidarityDial = cfg.GetString("services.grpc.solidarityservice.dial")
routing_service_type = cfg.GetString("routing.type")
valhalla_base_url = cfg.GetString("routing.valhalla.base_url")
)
mobilityAccounts, err := NewMobilityAccountService(mobilityAccountsDial)
if err != nil {
return nil, err
}
groupsManagement, err := NewGroupsManagementService(groupsManagementDial)
if err != nil {
return nil, err
}
fleetsSvc, err := NewFleetsService(fleetsDial)
if err != nil {
return nil, err
}
2022-09-05 05:25:05 +00:00
agendaSvc, err := NewAgendaService(agendaDial)
if err != nil {
return nil, err
}
2024-08-07 13:01:01 +00:00
solidarityService, err := NewSolidarityService(solidarityDial)
2024-08-02 13:02:35 +00:00
if err != nil {
return nil , err
}
2024-08-07 13:01:01 +00:00
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
}
2024-07-31 11:33:38 +00:00
return &ServicesHandler{
GRPC: GRPCServices{
MobilityAccounts: mobilityAccounts,
GroupsManagement: groupsManagement,
Fleets: fleetsSvc,
2022-09-05 05:25:05 +00:00
Agenda: agendaSvc,
2024-08-07 13:01:01 +00:00
SolidarityService: solidarityService,
Routing: routing,
},
}, nil
}