silvermobi/main.go

52 lines
1.2 KiB
Go

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() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
cfg, err := ReadConfig()
if err != nil {
panic(err)
}
var (
grpcEnable = cfg.GetBool("services.external.grpc.enable")
svc *services.ServiceHandler
stg storage.Storage
hdl *handler.SilverMobiHandler
)
if svc, err = services.NewServicesHandler(cfg); err != nil {
log.Fatal().Err(err).Msg("failed starting services handler")
}
if stg, err = storage.NewPostgresqlStorage(cfg); err != nil {
log.Fatal().Err(err).Msg("failed starting storage handler")
}
if hdl, err = handler.NewSilverMobiHandler(cfg, svc, stg); err != nil {
log.Fatal().Err(err).Msg("failed starting ridygo handler")
}
failed := make(chan error)
if grpcEnable {
log.Info().Msg("Running gRPC server")
go grpcserver.Run(failed, cfg, hdl)
}
err = <-failed
log.Fatal().Err(err).Msg("Terminating")
}