shorgru/pkg/middleware/context.go

22 lines
401 B
Go
Raw Normal View History

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)
}
}
}