huma-middleware
- Original
- Go
- v0.2.0
Router-agnostic middleware for Huma v2
(humago, humachi, humagin, and others). Each middleware lives in its own
package so an application links only the dependencies of the ones it uses.
Install
Go Module
go get github.com/blackbirdworks/huma-middleware
Included Packages
| Package | Layer | What it provides |
|---|---|---|
middleware/cleanpath |
net/http |
Normalizes request paths (//a/../b to /b) before router matching. |
middleware/tracing |
Huma | OpenTelemetry server spans (METHOD /route/{template}) and otelhttp HTTP metrics. |
middleware/logging |
Huma | Request-scoped log/slog logger stored in context with per-request field enrichment. |
middleware/accesslog |
Huma | One allocation-free structured access log record per request. |
middleware/recovery |
Huma | Recovers panics, logs stack traces, marks the active span as error, and answers HTTP 500. |
middleware/compression |
Huma | Content-aware zstd, brotli, and gzip compression (1024 B min, skips text/event-stream & pre-compressed media). |
Usage Example
Go
mux := http.NewServeMux()
api := humago.New(mux, huma.DefaultConfig("example", "1.0.0"))
api.UseMiddleware(
tracing.New(tracing.WithSkipPaths("/healthz")),
recovery.New(),
logging.New(),
accesslog.New(),
compression.New(),
)
handler := cleanpath.Handler(mux) // wrap before routing