one-api/middleware/request-id.go
2025-01-31 17:54:04 +08:00

19 lines
391 B
Go

package middleware
import (
"github.com/gin-gonic/gin"
"github.com/songquanpeng/one-api/common/helper"
)
func RequestId() func(c *gin.Context) {
return func(c *gin.Context) {
id := helper.GenRequestID()
c.Set(helper.RequestIdKey, id)
ctx := helper.SetRequestID(c.Request.Context(), id)
c.Request = c.Request.WithContext(ctx)
c.Header(helper.RequestIdKey, id)
c.Next()
}
}