mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-25 19:36:07 +00:00
24 lines
450 B
Go
24 lines
450 B
Go
package middleware
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// RequestId 自动增加requestId
|
|
func RequestId(trafficKey string) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
requestId := c.GetHeader(trafficKey)
|
|
if requestId == "" {
|
|
requestId = c.GetHeader(strings.ToLower(trafficKey))
|
|
}
|
|
if requestId == "" {
|
|
requestId = uuid.New().String()
|
|
}
|
|
c.Header(trafficKey, requestId)
|
|
c.Next()
|
|
}
|
|
}
|