howmuch/internal/pkg/middleware/requestid.go

21 lines
360 B
Go
Raw Normal View History

2024-10-03 11:41:32 +00:00
package middleware
import "github.com/gin-gonic/gin"
2024-10-03 11:48:36 +00:00
const requestID = "X-Request-Id"
2024-10-03 11:41:32 +00:00
func RequestID() gin.HandlerFunc {
return func(ctx *gin.Context) {
2024-10-03 11:48:36 +00:00
var rid string
if rid = ctx.GetString(requestID); rid != "" {
// request id exists already
ctx.Next()
}
if rid = ctx.GetHeader(requestID); rid != "" {
ctx.Set(requestID, rid)
}
2024-10-03 11:41:32 +00:00
}
}