middleware

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestIDHeader is the HTTP header for request correlation.
	RequestIDHeader = "X-Request-ID"

	// RequestIDKey is the Gin context key for the request ID.
	RequestIDKey = "request_id"
)

Variables

This section is empty.

Functions

func RequestID

func RequestID() gin.HandlerFunc

RequestID injects a unique request ID into every request. If the client sends X-Request-ID, it is reused. Otherwise, the OTel TraceID from the active span is used (providing log↔trace correlation for free). Falls back to a new UUID when no trace context exists.

func UserSpanAttributes

func UserSpanAttributes() gin.HandlerFunc

UserSpanAttributes reads the X-User-ID header injected by Oathkeeper and sets it as an attribute on the active OTel span. This allows filtering traces by authenticated user in Grafana Tempo.

func ZapLogger

func ZapLogger(logger *zap.Logger) gin.HandlerFunc

ZapLogger returns a Gin middleware that logs every HTTP request using zap. Each log line includes method, path, sanitized query, status, latency, client IP, body size, and request ID.

func ZapRecovery

func ZapRecovery(logger *zap.Logger) gin.HandlerFunc

ZapRecovery returns a Gin middleware that recovers from panics and logs them with zap. It returns a structured JSON error response so clients can handle the failure gracefully.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL