Documentation
¶
Index ¶
- Constants
- func CorrelationIDMiddleware(baseLogger *slog.Logger) func(http.Handler) http.Handler
- func ErrorHandlingMiddleware(logger *slog.Logger) func(http.Handler) http.Handler
- func GetCorrelationID(r *http.Request) string
- func GetLogger(r *http.Request, fallback *slog.Logger) *slog.Logger
- func LoggingMiddleware(logger *slog.Logger) func(http.Handler) http.Handler
- func MetricsMiddleware() func(http.Handler) http.Handler
Constants ¶
const ( // CorrelationIDHeader is the HTTP header name for correlation ID. CorrelationIDHeader = gohttpkit.CorrelationIDHeader )
Variables ¶
This section is empty.
Functions ¶
func CorrelationIDMiddleware ¶
CorrelationIDMiddleware reads or generates X-Correlation-ID, stores it and a correlation-aware *slog.Logger in the request context, and echoes the ID in the response header.
Must be the outermost middleware so all subsequent handlers have access to a correlation-aware logger.
func ErrorHandlingMiddleware ¶
ErrorHandlingMiddleware recovers from panics, logs them, and writes a 500 response using the project's ErrorResponse type.
func GetCorrelationID ¶
GetCorrelationID returns the correlation ID stored by CorrelationIDMiddleware.
func GetLogger ¶
GetLogger returns the correlation-aware logger stored by CorrelationIDMiddleware, falling back to fallback when the middleware has not run.
func LoggingMiddleware ¶
LoggingMiddleware logs each request (method, path, status, latency) after the downstream handler completes. Uses the correlation-aware logger stored by CorrelationIDMiddleware when available.
Must be registered after CorrelationIDMiddleware.
func MetricsMiddleware ¶
MetricsMiddleware records HTTP request metrics via Prometheus.
When registered as a per-route middleware (inside the mux, via StdHTTPServerOptions.Middlewares), r.Pattern carries the route template (e.g. "GET /api/llm-providers/{id}"), giving low-cardinality labels. When registered as outer middleware, r.Pattern is empty and r.URL.Path is used as a fallback.
Types ¶
This section is empty.