包含Go API项目的所有源代码、配置文件、Docker配置、文档和前端资源 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
19 lines
418 B
Go
19 lines
418 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gin-gonic/gin"
|
|
"one-api/common"
|
|
)
|
|
|
|
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()
|
|
}
|
|
}
|