diff options
author | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-12-09 01:07:15 +0300 |
---|---|---|
committer | Alexander Neonxp Kiryukhin <i@neonxp.ru> | 2024-12-09 01:07:15 +0300 |
commit | 34ccc98a942098faefb5f4211b215ff9ccc7ad0e (patch) | |
tree | 7696ab4d7c8d9fb09c7e2575d482517f68824ae3 /pkg/middleware/context.go |
Начальный
Diffstat (limited to 'pkg/middleware/context.go')
-rw-r--r-- | pkg/middleware/context.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/pkg/middleware/context.go b/pkg/middleware/context.go new file mode 100644 index 0000000..f9c4425 --- /dev/null +++ b/pkg/middleware/context.go @@ -0,0 +1,21 @@ +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) + } + } +} |