go-app/pkg/app/run_grpc.go

36 lines
865 B
Go

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: a.cfg.GRPC.GRPCGatewayPath,
StripPrefix: true,
Handler: a.GRPC.GetGatewayMux(),
})
span.AddEvent("GRPC Gateway Mux Registered")
}
}