2021-12-21 13:16:54 +00:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2022-01-17 06:02:13 +00:00
|
|
|
// GinContextToContextMiddleware is a middleware to add gin context in context
|
2021-12-21 13:16:54 +00:00
|
|
|
func GinContextToContextMiddleware() gin.HandlerFunc {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
ctx := context.WithValue(c.Request.Context(), "GinContextKey", c)
|
|
|
|
c.Request = c.Request.WithContext(ctx)
|
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|