one-api/middleware/request-id.go
JustSong 9026ec7510
Some checks failed
Publish Docker image (amd64, English) / Push Docker image to multiple registries (push) Has been cancelled
Publish Docker image (amd64) / Push Docker image to multiple registries (push) Has been cancelled
feat: support cloudflare now
2024-04-26 23:05:48 +08:00

19 lines
420 B
Go

package middleware
import (
"context"
"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 := context.WithValue(c.Request.Context(), helper.RequestIdKey, id)
c.Request = c.Request.WithContext(ctx)
c.Header(helper.RequestIdKey, id)
c.Next()
}
}