Compare commits
2 Commits
89f016ed9d
...
b44b6a331c
Author | SHA1 | Date | |
---|---|---|---|
b44b6a331c | |||
adfedc9239 |
@ -18,7 +18,7 @@ func (a *appGRPCServer) registerServiceGatewayHandlers(ctx context.Context, serv
|
|||||||
if len(service.GwRegistrationFuncs) < 1 {
|
if len(service.GwRegistrationFuncs) < 1 {
|
||||||
return
|
return
|
||||||
} else if a.gatewayMux == nil {
|
} else if a.gatewayMux == nil {
|
||||||
a.gatewayMux = runtime.NewServeMux()
|
a.gatewayMux = runtime.NewServeMux(a.opts.GRPCGatewayOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, span := a.tracer.Start(ctx, "appgrpc.init.prepare.service.gwHandlers", trace.WithAttributes(
|
ctx, span := a.tracer.Start(ctx, "appgrpc.init.prepare.service.gwHandlers", trace.WithAttributes(
|
||||||
@ -50,6 +50,7 @@ func (a *appGRPCServer) GetClientConn(ctx context.Context) *grpc.ClientConn {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
span.RecordError(err)
|
span.RecordError(err)
|
||||||
span.SetStatus(codes.Error, err.Error())
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientConn
|
return clientConn
|
||||||
|
@ -20,6 +20,7 @@ type AppGRPC struct {
|
|||||||
StreamInterceptors []grpc.StreamServerInterceptor
|
StreamInterceptors []grpc.StreamServerInterceptor
|
||||||
GRPCOpts []grpc.ServerOption
|
GRPCOpts []grpc.ServerOption
|
||||||
GRPCDialOpts []grpc.DialOption // Map ServerOptions to DialOpts for GRPC Gateway support
|
GRPCDialOpts []grpc.DialOption // Map ServerOptions to DialOpts for GRPC Gateway support
|
||||||
|
GRPCGatewayOpts []runtime.ServeMuxOption // Configure grpc-gateway ServeMux
|
||||||
GRPCDone <-chan error
|
GRPCDone <-chan error
|
||||||
gatewayMux *runtime.ServeMux
|
gatewayMux *runtime.ServeMux
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
@ -60,6 +61,13 @@ func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
|
|||||||
// Inject extra handlers if given
|
// Inject extra handlers if given
|
||||||
// Used for grpc-gateway runtime.ServeMux handlers
|
// Used for grpc-gateway runtime.ServeMux handlers
|
||||||
for _, h := range opts.Handlers {
|
for _, h := range opts.Handlers {
|
||||||
|
// prefix must end in / to route sub-paths
|
||||||
|
if !strings.HasSuffix(h.Prefix, "/") {
|
||||||
|
h.Prefix = h.Prefix + "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
// if enabled, the path prefix is stripped before
|
||||||
|
// requests are sent to the handler
|
||||||
if h.StripPrefix {
|
if h.StripPrefix {
|
||||||
h.Handler = http.StripPrefix(h.Prefix, h.Handler)
|
h.Handler = http.StripPrefix(h.Prefix, h.Handler)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user