Changeset 0.33.0 (#207)

Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit is contained in:
2026-03-19 21:37:32 +00:00
committed by xcaliber
parent b1266b0d7c
commit ed3e9363f2
42 changed files with 2527 additions and 129 deletions

View File

@@ -0,0 +1,28 @@
package middleware
import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
const (
// RequestIDKey is the Gin context key for the request ID.
RequestIDKey = "request_id"
// RequestIDHeader is the HTTP header used to propagate request IDs.
RequestIDHeader = "X-Request-Id"
)
// RequestID generates a UUID per request and sets it in the Gin context
// and response header. If the incoming request already carries an
// X-Request-Id header, it is preserved (useful for tracing across proxies).
func RequestID() gin.HandlerFunc {
return func(c *gin.Context) {
id := c.GetHeader(RequestIDHeader)
if id == "" {
id = uuid.New().String()
}
c.Set(RequestIDKey, id)
c.Header(RequestIDHeader, id)
c.Next()
}
}