implement grpc gateway and addl handler support
This commit is contained in:
@ -57,6 +57,15 @@ func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
|
||||
Msg("mounted prometheus metrics endpoint")
|
||||
}
|
||||
|
||||
// Inject extra handlers if given
|
||||
// Used for grpc-gateway runtime.ServeMux handlers
|
||||
for _, h := range opts.Handlers {
|
||||
if h.StripPrefix {
|
||||
h.Handler = http.StripPrefix(h.Prefix, h.Handler)
|
||||
}
|
||||
mux.Handle(h.Prefix, h.Handler)
|
||||
}
|
||||
|
||||
// Add OTEL, skip health-check spans
|
||||
// NOTE: Add any other span exclusions here
|
||||
handler := otelhttp.NewHandler(mux, "/",
|
||||
|
@ -8,8 +8,9 @@ import (
|
||||
|
||||
type AppHTTP struct {
|
||||
Ctx context.Context
|
||||
Funcs []HTTPFunc
|
||||
Middleware []http.Handler
|
||||
Funcs []HTTPFunc // Handler funcs, will be wrapped with OTEL
|
||||
Middleware []http.Handler // Middleware (e.g. request logging)
|
||||
Handlers []HTTPHandler // Raw Handler/Mux to add, optional prefix stripping
|
||||
HealthChecks []HealthCheckFunc
|
||||
CustomListener net.Listener
|
||||
HTTPDone <-chan any
|
||||
@ -20,4 +21,10 @@ type HTTPFunc struct {
|
||||
HandlerFunc http.HandlerFunc
|
||||
}
|
||||
|
||||
type HTTPHandler struct {
|
||||
Prefix string // path prefix under which to serve this handler/mux
|
||||
StripPrefix bool // strip path before sending to handler/mux
|
||||
Handler http.Handler
|
||||
}
|
||||
|
||||
type HealthCheckFunc func(context.Context) error
|
||||
|
Reference in New Issue
Block a user