summaryrefslogblamecommitdiff
path: root/pkg/middleware/context.go
blob: f9c4425b8cd50459fa080752a362949e451dc8a9 (plain) (tree)




















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