blob: 6271e438c10af512118c6fd1ee3afdea7ddf7fcf (
plain) (
tree)
|
|
package middleware
import (
"context"
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
)
func User() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
sess, err := session.Get("user", c)
if err != nil {
return err
}
u := sess.Values["user"]
c.Set("user", u)
ctx := context.WithValue(c.Request().Context(), ContextKey("user"), u)
r := c.Request().WithContext(ctx)
c.SetRequest(r)
return next(c)
}
}
}
|