parcoursmob/services/services.go

58 lines
1.5 KiB
Go

package services
import (
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"
"github.com/spf13/viper"
)
type ServicesHandler struct {
GRPC GRPCServices
}
type GRPCServices struct {
MobilityAccounts mobilityaccounts.MobilityAccountsClient
GroupsManagement groupsmanagement.GroupsManagementClient
Fleets fleets.FleetsClient
Agenda agenda.AgendaClient
}
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")
agendaDial = cfg.GetString("services.grpc.agenda.dial")
)
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
}
agendaSvc, err := NewAgendaService(agendaDial)
if err != nil {
return nil, err
}
return &ServicesHandler{
GRPC: GRPCServices{
MobilityAccounts: mobilityAccounts,
GroupsManagement: groupsManagement,
Fleets: fleetsSvc,
Agenda: agendaSvc,
},
}, nil
}