diags/main.go

53 lines
974 B
Go
Raw Normal View History

2024-11-20 10:01:04 +00:00
package main
import (
"os"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"git.coopgo.io/coopgo-platform/diags/grpcapi"
"git.coopgo.io/coopgo-platform/diags/handlers"
"git.coopgo.io/coopgo-platform/diags/storage"
2024-11-20 13:31:46 +00:00
)
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})
}
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")
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")
}