carpool-incentives/main.go

57 lines
1.2 KiB
Go

package main
import (
"fmt"
"os"
grpcserver "git.coopgo.io/coopgo-platform/carpool-incentives/grpc/server"
"git.coopgo.io/coopgo-platform/carpool-incentives/handlers/incentives"
"git.coopgo.io/coopgo-platform/carpool-incentives/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")
)
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
}
incentives_handler, err := incentives.NewIncentivesHandler(cfg, storage)
if err != nil {
log.Fatal().Err(err).Msg("could not initiate incentives handler")
return
}
failed := make(chan error)
if grpc_enable {
log.Info().Msg("Running gRPC server")
go grpcserver.Run(failed, cfg, incentives_handler)
}
err = <-failed
log.Fatal().Err(err).Msg("Terminating")
}