22 lines
401 B
Go
22 lines
401 B
Go
|
package middleware
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/labstack/echo/v4"
|
||
|
)
|
||
|
|
||
|
type ContextKey string
|
||
|
|
||
|
func Context(key ContextKey, value any) echo.MiddlewareFunc {
|
||
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||
|
return func(c echo.Context) error {
|
||
|
ctx := context.WithValue(c.Request().Context(), key, value)
|
||
|
r := c.Request().WithContext(ctx)
|
||
|
c.SetRequest(r)
|
||
|
|
||
|
return next(c)
|
||
|
}
|
||
|
}
|
||
|
}
|