|
|
|
|
@@ -59,17 +59,30 @@ func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
|
|
|
|
|
// Inject extra handlers if given
|
|
|
|
|
// Used for grpc-gateway runtime.ServeMux handlers
|
|
|
|
|
for _, h := range opts.Handlers {
|
|
|
|
|
// prefix must end in / to route sub-paths
|
|
|
|
|
if !strings.HasSuffix(h.Prefix, "/") {
|
|
|
|
|
h.Prefix = h.Prefix + "/"
|
|
|
|
|
var servePath string
|
|
|
|
|
|
|
|
|
|
if h.Pattern != "" && h.Prefix != "" {
|
|
|
|
|
l.Fatal().Str("ExactPath", h.Pattern).Str("Prefix", h.Prefix).
|
|
|
|
|
Msg("Can't have both pattern and prefix match for http handler")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if enabled, the path prefix is stripped before
|
|
|
|
|
// requests are sent to the handler
|
|
|
|
|
if h.StripPrefix {
|
|
|
|
|
h.Handler = http.StripPrefix(h.Prefix[:len(h.Prefix)-1], h.Handler)
|
|
|
|
|
if h.Prefix != "" {
|
|
|
|
|
// prefix must end in / to route sub-paths
|
|
|
|
|
if !strings.HasSuffix(h.Prefix, "/") {
|
|
|
|
|
h.Prefix = h.Prefix + "/"
|
|
|
|
|
}
|
|
|
|
|
servePath = h.Prefix
|
|
|
|
|
|
|
|
|
|
// if enabled, the path prefix is stripped before
|
|
|
|
|
// requests are sent to the handler
|
|
|
|
|
if h.StripPrefix {
|
|
|
|
|
h.Handler = http.StripPrefix(h.Prefix[:len(h.Prefix)-1], h.Handler)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
servePath = h.Pattern
|
|
|
|
|
}
|
|
|
|
|
mux.Handle(h.Prefix, otelhttp.WithRouteTag(h.Prefix, h.Handler))
|
|
|
|
|
|
|
|
|
|
mux.Handle(h.Prefix, otelhttp.WithRouteTag(servePath, h.Handler))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add OTEL instrumentation, filter noise, set span names
|
|
|
|
|
|