feat(requestid): reqID in the header
This commit is contained in:
@ -2,8 +2,19 @@ package middleware
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
const requestID = "X-Request-Id"
|
||||
|
||||
func RequestID() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
ctx.Set("X-Request-Id", "123")
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user