implement grpc gateway and addl handler support
This commit is contained in:
35
pkg/app/run_grpc.go
Normal file
35
pkg/app/run_grpc.go
Normal file
@ -0,0 +1,35 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
|
||||
)
|
||||
|
||||
func (a *App) runGRPC(ctx context.Context) {
|
||||
span := trace.SpanFromContext(ctx)
|
||||
if err := a.initGRPC(ctx); err != nil {
|
||||
span.RecordError(err)
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
}
|
||||
span.AddEvent("grpc server started")
|
||||
span.SetAttributes(attribute.Int("grpc.services", len(a.GRPC.Services)))
|
||||
|
||||
if a.GRPC.GetGatewayMux() != nil {
|
||||
if a.HTTP.Handlers == nil {
|
||||
a.HTTP.Handlers = make([]opts.HTTPHandler, 0, 1)
|
||||
}
|
||||
|
||||
a.HTTP.Handlers = append(a.HTTP.Handlers, opts.HTTPHandler{
|
||||
Prefix: GRPC_GW_API_PATH,
|
||||
StripPrefix: true,
|
||||
Handler: a.GRPC.GetGatewayMux(),
|
||||
})
|
||||
|
||||
span.AddEvent("GRPC Gateway Mux Registered")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user