blob: 6271e438c10af512118c6fd1ee3afdea7ddf7fcf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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)
}
}
}
|