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:50:14 +00:00
|
|
|
ctx.Set("X-Request-Id", "123")
|
2024-10-03 11:41:32 +00:00
|
|
|
}
|
|
|
|
}
|