implement grpc gateway and addl handler support
This commit is contained in:
70
pkg/app/init.go
Normal file
70
pkg/app/init.go
Normal file
@ -0,0 +1,70 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||
srvgrpc "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc"
|
||||
grpcopts "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
|
||||
srvhttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http"
|
||||
)
|
||||
|
||||
func (a *App) initGRPC(ctx context.Context) error {
|
||||
ctx, span := a.tracer.Start(ctx, "init.grpc")
|
||||
defer span.End()
|
||||
|
||||
shutdown, doneChan, err := srvgrpc.InitGRPCServer(ctx,
|
||||
&grpcopts.GRPCOpts{
|
||||
GRPCConfig: a.cfg.GRPC,
|
||||
AppGRPC: a.GRPC,
|
||||
})
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
a.shutdownFuncs = append(a.shutdownFuncs, shutdown)
|
||||
a.GRPC.GRPCDone = doneChan
|
||||
|
||||
span.SetStatus(codes.Ok, "")
|
||||
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)),
|
||||
)
|
||||
|
||||
a.HTTP.Ctx = a.AppContext
|
||||
httpShutdown, a.HTTP.HTTPDone, err = srvhttp.InitHTTPServer(a.HTTP)
|
||||
|
||||
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)
|
||||
}
|
Reference in New Issue
Block a user