package app import ( "errors" "github.com/rs/zerolog" "go.opentelemetry.io/otel/codes" "gitea.libretechconsulting.com/rmcguire/go-app/pkg/config" ) // TODO: Make Configurable const GRPC_GW_API_PATH = "/api" func (a *App) Done() <-chan any { return a.appDone } func (a *App) MustRun() { if a.cfg != nil { panic(errors.New("already ran app trying to run")) } // Set up app a.cfg = config.MustFromCtx(a.AppContext) a.l = zerolog.Ctx(a.AppContext) a.shutdownFuncs = make([]shutdownFunc, 0) a.appDone = make(chan any) a.HTTP.HTTPDone = make(chan any) if !a.cfg.HTTPEnabled() && !a.cfg.GRPCEnabled() { panic(errors.New("neither http nor grpc enabled, nothing to do")) } if len(a.HTTP.Funcs) < 1 { a.l.Warn().Msg("no http funcs provided, only serving health and metrics") } // Start OTEL // Registers a NO-OP provider if not enabled a.initOTEL() // With OTEL ready, create an init span to track startup ctx, initSpan := a.tracer.Start(a.AppContext, "init") defer initSpan.End() // Prepare GRPC first. The GRPC server may update its opts // with a prepared GRPC-Gateway runtime.ServeMux if any of its services // have added GRPC-Gateway handlers. If present, serve under api path if a.cfg.GRPCEnabled() { a.runGRPC(ctx) } if a.cfg.HTTPEnabled() { a.runHTTP(ctx) } // Monitor app lifecycle go a.monitor() // Startup Complete a.l.Info(). Str("name", a.cfg.Name). Str("version", a.cfg.Version). Str("logLevel", a.cfg.Logging.Level). Msg("app initialized") initSpan.SetStatus(codes.Ok, "") }