go-app/pkg/app/app_init.go

58 lines
1.3 KiB
Go
Raw Normal View History

2025-03-06 17:16:27 -05:00
package app
import (
"context"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
2025-03-07 08:42:38 -05:00
srvhttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http"
2025-03-06 17:16:27 -05:00
)
2025-03-07 13:00:45 -05:00
// TODO: Implement
func (a *App) initGRPC(ctx context.Context) error {
return nil
2025-03-06 17:16:27 -05:00
}
func (a *App) initHTTP(ctx context.Context) error {
var err error
var httpShutdown shutdownFunc
_, span := a.tracer.Start(ctx, "init.http")
defer span.End()
span.SetAttributes(
attribute.Int("numHTTPFuncs", len(a.HTTP.Funcs)),
attribute.Int("numHTTPMiddlewares", len(a.HTTP.Middleware)),
attribute.Int("numHTTPHealthChecks", len(a.HTTP.HealthChecks)),
)
2025-03-07 08:42:38 -05:00
httpShutdown, a.HTTP.httpDone, err = srvhttp.InitHTTPServer(
&srvhttp.HTTPServerOpts{
2025-03-06 17:16:27 -05:00
Ctx: a.AppContext,
HandleFuncs: a.HTTP.Funcs,
Middleware: a.HTTP.Middleware,
HealthCheckFuncs: a.HTTP.HealthChecks,
},
)
a.shutdownFuncs = append(a.shutdownFuncs, httpShutdown)
if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, err.Error())
} else {
span.SetStatus(codes.Ok, "")
}
return err
}
func (a *App) initOTEL() {
var otelShutdown shutdownFunc
a.AppContext, otelShutdown = otel.Init(a.AppContext)
a.shutdownFuncs = append(a.shutdownFuncs, otelShutdown)
a.tracer = otel.MustTracerFromCtx(a.AppContext)
}