solidarity-transport/main.go

63 lines
1.5 KiB
Go

package main
import (
"os"
routing "git.coopgo.io/coopgo-platform/routing-service"
"git.coopgo.io/coopgo-platform/solidarity-transport/handler"
grpcserver "git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/server"
"git.coopgo.io/coopgo-platform/solidarity-transport/storage"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
cfg, err := ReadConfig()
if err != nil {
panic(err)
}
var (
service_name = cfg.GetString("name")
grpc_enable = cfg.GetBool("services.grpc.enable")
dev_env = cfg.GetBool("dev_env")
routing_service_type = cfg.GetString("routing.type")
valhalla_base_url = cfg.GetString("routing.valhalla.base_url")
)
if dev_env {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
log.Info().Msg("Running " + service_name)
storage, err := storage.NewStorage(cfg)
if err != nil {
log.Fatal().Err(err).Msg("could not initiate storage")
return
}
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
}
handler, err := handler.NewSolidarityTransportHandler(cfg, storage, routing)
if err != nil {
log.Fatal().Err(err).Msg("could not initialize solidarity transport handler")
return
}
failed := make(chan error)
if grpc_enable {
log.Info().Msg("Running grpc server")
go grpcserver.Run(failed, cfg, handler)
}
err = <-failed
log.Fatal().Err(err).Msg("Terminating")
}