mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 07:19:55 +00:00
20 lines
442 B
Go
20 lines
442 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func RequestId() func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
id := common.GetTimeString() + common.GetRandomString(8)
|
|
c.Set(common.RequestIdKey, id)
|
|
ctx := context.WithValue(c.Request.Context(), common.RequestIdKey, id)
|
|
c.Request = c.Request.WithContext(ctx)
|
|
c.Header(common.RequestIdKey, id)
|
|
c.Next()
|
|
}
|
|
}
|