silvermobi/main.go

52 lines
1.2 KiB
Go
Raw Normal View History

2023-08-08 10:28:43 +00:00
package main
import (
"git.coopgo.io/coopgo-apps/silvermobi/handler"
grpcserver "git.coopgo.io/coopgo-apps/silvermobi/servers/grpcapi/server"
"git.coopgo.io/coopgo-apps/silvermobi/services"
"git.coopgo.io/coopgo-apps/silvermobi/storage"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
2024-10-31 19:32:54 +00:00
2023-08-08 10:28:43 +00:00
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
cfg, err := ReadConfig()
2024-10-31 19:32:54 +00:00
2023-08-08 10:28:43 +00:00
if err != nil {
panic(err)
}
var (
2024-10-31 19:32:54 +00:00
grpcEnable = cfg.GetBool("services.external.grpc.enable")
svc *services.ServiceHandler
stg storage.Storage
hdl *handler.SilverMobiHandler
2023-08-08 10:28:43 +00:00
)
2024-10-31 19:32:54 +00:00
if svc, err = services.NewServicesHandler(cfg); err != nil {
2023-08-08 10:28:43 +00:00
log.Fatal().Err(err).Msg("failed starting services handler")
}
2024-10-31 19:32:54 +00:00
if stg, err = storage.NewPostgresqlStorage(cfg); err != nil {
2023-08-08 10:28:43 +00:00
log.Fatal().Err(err).Msg("failed starting storage handler")
}
2024-10-31 19:32:54 +00:00
if hdl, err = handler.NewSilverMobiHandler(cfg, svc, stg); err != nil {
2023-08-08 10:28:43 +00:00
log.Fatal().Err(err).Msg("failed starting ridygo handler")
}
2024-10-31 19:32:54 +00:00
2023-08-08 10:28:43 +00:00
failed := make(chan error)
2024-10-31 19:32:54 +00:00
if grpcEnable {
2023-08-08 10:28:43 +00:00
log.Info().Msg("Running gRPC server")
2024-10-31 19:32:54 +00:00
go grpcserver.Run(failed, cfg, hdl)
2023-08-08 10:28:43 +00:00
}
err = <-failed
log.Fatal().Err(err).Msg("Terminating")
}