48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/rs/zerolog"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/codes"
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
optsgrpc "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/grpc/opts"
|
|
optshttp "gitea.libretechconsulting.com/rmcguire/go-app/pkg/srv/http/opts"
|
|
)
|
|
|
|
func (a *App) runGRPC(ctx context.Context) {
|
|
if a.GRPC == nil {
|
|
a.GRPC = &optsgrpc.AppGRPC{
|
|
GRPCDone: make(chan error),
|
|
}
|
|
}
|
|
if !a.cfg.GRPCEnabled() {
|
|
zerolog.Ctx(ctx).Info().Msg("skipping disabled GRPC server")
|
|
return
|
|
}
|
|
|
|
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([]optshttp.HTTPHandler, 0, 1)
|
|
}
|
|
|
|
a.HTTP.Handlers = append(a.HTTP.Handlers, optshttp.HTTPHandler{
|
|
Prefix: a.cfg.GRPC.GRPCGatewayPath,
|
|
StripPrefix: true,
|
|
Handler: a.GRPC.GetGatewayMux(),
|
|
})
|
|
|
|
span.AddEvent("GRPC Gateway Mux Registered")
|
|
}
|
|
}
|