mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
修改中间件结构
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
func RequestId() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// Check for incoming header, use it if exists
|
||||
requestId := c.Request.Header.Get("X-Request-Id")
|
||||
|
||||
// Create request id with UUID4
|
||||
if requestId == "" {
|
||||
u4 := uuid.NewV4()
|
||||
requestId = u4.String()
|
||||
}
|
||||
|
||||
// Expose it for use in the application
|
||||
c.Set("X-Request-Id", requestId)
|
||||
|
||||
// Set X-Request-Id header
|
||||
c.Writer.Header().Set("X-Request-Id", requestId)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user