solidarity-service/main.go

60 lines
1.6 KiB
Go
Raw Normal View History

2023-10-20 11:41:39 +00:00
package main
import (
routing "git.coopgo.io/coopgo-platform/routing-service"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
SolidarityServiceHandler "solidarity-service/handler"
api "solidarity-service/interoperability/solidarity-api/server"
grpcserver "solidarity-service/servers/grpc/server"
"solidarity-service/storage"
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
cfg, err := ReadConfig()
if err != nil {
panic(err)
}
var (
2023-12-08 06:31:41 +00:00
serviceName = cfg.GetString("name")
grpcEnable = cfg.GetBool("services.grpc.enable")
solidarityApiEnable = cfg.GetBool("services.solidarity-api.enable")
routingServiceType = cfg.GetString("routing.type")
valhallaBaseUrl = cfg.GetString("routing.valhalla.base_url")
2023-10-20 11:41:39 +00:00
)
2023-12-08 06:31:41 +00:00
log.Info().Msg("Running " + serviceName)
2023-10-20 11:41:39 +00:00
storageService, err := storage.NewStorage(cfg)
if err != nil {
log.Fatal().Err(err).Msg("Could not initiate the storage service")
return
}
2023-12-08 06:31:41 +00:00
routing, err := routing.NewRoutingService(routingServiceType, valhallaBaseUrl)
2023-10-20 11:41:39 +00:00
if err != nil {
log.Fatal().Err(err).Msg("Could not initiate the routing service")
return
}
handler, err := SolidarityServiceHandler.NewSolidarityServiceHandler(cfg, routing, storageService)
if err != nil {
log.Fatal().Err(err).Msg("Could not initiate the solidarity service handler")
return
}
failed := make(chan error)
2023-12-08 06:31:41 +00:00
if grpcEnable {
2023-10-20 11:41:39 +00:00
log.Info().Msg("Running gRPC server")
go grpcserver.Run(failed, cfg, handler)
}
2023-12-08 06:31:41 +00:00
if solidarityApiEnable {
log.Info().Msg("Running Interoperability REST API")
2023-10-20 11:41:39 +00:00
go api.Run(cfg, handler, storageService)
}
err = <-failed
log.Fatal().Err(err).Msg("Terminating")
}