24 lines
514 B
Go
24 lines
514 B
Go
package middleware
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func RequestId() func(c *gin.Context) {
|
|
return func(c *gin.Context) {
|
|
if c.Request.URL.Path == "/v1/responses" {
|
|
c.Set("request_received_at", time.Now())
|
|
}
|
|
id := common.NewRequestId()
|
|
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()
|
|
}
|
|
}
|