58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/codes"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
|
srvhttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http"
|
|
)
|
|
|
|
// TODO: Implement
|
|
func (a *App) initGRPC(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
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)),
|
|
)
|
|
|
|
httpShutdown, a.HTTP.httpDone, err = srvhttp.InitHTTPServer(
|
|
&srvhttp.HTTPServerOpts{
|
|
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)
|
|
}
|