-
Hi !
======
but I don't know how to get the data from this ?
it works but i got :
changed to the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to cast into correct type value, ok := c.Get("KEY").(time.Time)
if !ok {
return errors.New("invalid type for KEY")
} NB: if you set it as pointer you need to cast it back to pointer. Or if you set value into context and its type is pointer to or longer example: func main() {
e := echo.New()
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Set("KEY", time.Now())
return next(c)
}
})
e.GET("/", func(c echo.Context) error {
value, ok := c.Get("KEY").(time.Time)
if !ok {
return errors.New("invalid type for KEY")
}
return c.JSON(http.StatusOK, map[string]time.Time{"time": value})
})
if err := e.Start(":8080"); err != http.ErrServerClosed {
log.Fatal(err)
}
} |
Beta Was this translation helpful? Give feedback.
You need to cast into correct type
NB: if you set it as pointer you need to cast it back to pointer. Or if you set value into context and its type is pointer to
token.Payload
you need to cast it back to*token.Payload
when you Get it from token.api.Payload
is different type/struct I assume.or longer example: