-
Hey, Thanks in advance for your help :) |
Beta Was this translation helpful? Give feedback.
Answered by
aldas
Jun 4, 2022
Replies: 1 comment 1 reply
-
Context has func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Set("claim", "claim") // add value to context store
return next(c)
}
})
e.GET("/", func(c echo.Context) error {
claim, ok := c.Get("claim").(string) // extract value from context and cast it into string
if !ok {
return c.String(http.StatusInternalServerError, "missing claim or cast failure")
}
return c.String(http.StatusOK, claim)
})
if err := e.Start(":8080"); err != http.ErrServerClosed {
log.Fatal(err)
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Bean900
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context has
Set
andGet
methods that you can use.