agenda/main.go

53 lines
977 B
Go
Raw Permalink Normal View History

2022-09-05 05:27:52 +00:00
package main
import (
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
2022-09-05 05:27:52 +00:00
"git.coopgo.io/coopgo-platform/agenda/grpcapi"
"git.coopgo.io/coopgo-platform/agenda/handlers"
"git.coopgo.io/coopgo-platform/agenda/storage"
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
2022-09-05 05:27:52 +00:00
cfg, err := ReadConfig()
if err != nil {
panic(err)
}
var (
service_name = cfg.GetString("name")
grpc_enable = cfg.GetBool("services.grpc.enable")
2023-03-10 12:19:01 +00:00
dev_env = cfg.GetBool("dev_env")
2022-09-05 05:27:52 +00:00
)
if dev_env {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
2022-09-05 05:27:52 +00:00
storage, err := storage.NewStorage(cfg)
if err != nil {
panic(err)
}
handler := handlers.NewHandler(cfg, storage)
failed := make(chan error)
log.Info().Str("service_name", service_name).Msg("Running service")
2022-09-05 05:27:52 +00:00
if grpc_enable {
go grpcapi.Run(failed, cfg, handler)
}
// Terminate if one of the services fails
err = <-failed
log.Fatal().Err(err).Msg("Terminating server")
2022-09-05 05:27:52 +00:00
}