mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-01 15:46:38 +08:00
handling, remove redundant return statements, correct gorm tag syntax, and improve type assertions in relay.go
24 lines
505 B
Go
24 lines
505 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"one-api/common"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func RequestId() func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
type RequestIdKeyType string
|
|
|
|
const RequestIdKey RequestIdKeyType = common.RequestIdKey
|
|
|
|
id := common.GetTimeString() + common.GetRandomString(8)
|
|
c.Set(common.RequestIdKey, id)
|
|
ctx := context.WithValue(c.Request.Context(), RequestIdKey, id)
|
|
c.Request = c.Request.WithContext(ctx)
|
|
c.Header(common.RequestIdKey, id)
|
|
c.Next()
|
|
}
|
|
}
|