2023-09-17 07:39:46 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/gin-gonic/gin"
|
2024-01-28 11:38:58 +00:00
|
|
|
"github.com/songquanpeng/one-api/common/helper"
|
2023-09-17 07:39:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func RequestId() func(c *gin.Context) {
|
|
|
|
return func(c *gin.Context) {
|
2024-03-13 17:02:47 +00:00
|
|
|
id := helper.GenRequestID()
|
2024-04-26 15:05:48 +00:00
|
|
|
c.Set(helper.RequestIdKey, id)
|
|
|
|
ctx := context.WithValue(c.Request.Context(), helper.RequestIdKey, id)
|
2023-09-17 07:39:46 +00:00
|
|
|
c.Request = c.Request.WithContext(ctx)
|
2024-04-26 15:05:48 +00:00
|
|
|
c.Header(helper.RequestIdKey, id)
|
2023-09-17 07:39:46 +00:00
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|