package main import ( "fmt" "os" "git.coopgo.io/coopgo-platform/carpool-service/handler" grpcserver "git.coopgo.io/coopgo-platform/carpool-service/servers/grpc/server" ocssapi "git.coopgo.io/coopgo-platform/carpool-service/servers/ocss-api" "git.coopgo.io/coopgo-platform/carpool-service/storage" "git.coopgo.io/coopgo-platform/carpool-service/tiles" "git.coopgo.io/coopgo-platform/routing-service" "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") ocss_enable = cfg.GetBool("services.ocss_api.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}) fmt.Printf("\033]0;%s\007", service_name) } 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 } tilesHandler, err := tiles.NewTilesHandler(cfg, storage) if err != nil { log.Fatal().Err(err).Msg("could not initialize tiles handler") return } handler, err := handler.NewCarpoolServiceHandler(cfg, storage, tilesHandler, routing) if err != nil { log.Fatal().Err(err).Msg("could not initiate carpoool service handler") return } failed := make(chan error) if grpc_enable { log.Info().Msg("Running gRPC server") go grpcserver.Run(failed, cfg, handler) } if ocss_enable { log.Info().Msg("Running OCSS REST API") go ocssapi.Run(failed, cfg, handler) } err = <-failed log.Fatal().Err(err).Msg("Terminating") }