framework/pkg/middleware/context.go

22 lines
401 B
Go
Raw Permalink Normal View History

2024-10-12 02:52:22 +03:00
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)
}
}
}