-
I initialized the middleware.
I can see the X-Request-Id header entry in the response. However, I am unable to obtain the RequestId within the request/response cycle.
|
Beta Was this translation helpful? Give feedback.
Answered by
aldas
Sep 6, 2022
Replies: 1 comment 1 reply
-
I am able see get id with this example: func main() {
e := echo.New()
e.Use(middleware.RequestID())
e.GET("/", func(c echo.Context) error {
id := c.Response().Header().Get(echo.HeaderXRequestID)
return c.String(http.StatusOK, id)
})
if err := e.Start(":8080"); err != http.ErrServerClosed {
e.Logger.Fatal(err)
}
} that middleware config has also func main() {
e := echo.New()
e.Use(middleware.RequestIDWithConfig(middleware.RequestIDConfig{
RequestIDHandler: func(c echo.Context, s string) {
c.Set("MY_REQUEST_ID", s)
},
}))
e.GET("/", func(c echo.Context) error {
id, _ := c.Get("MY_REQUEST_ID").(string)
return c.String(http.StatusOK, id)
})
if err := e.Start(":8080"); err != http.ErrServerClosed {
e.Logger.Fatal(err)
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
terzano
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am able see get id with this example:
that middleware config has also
RequestIDHandler
that you can use to set id value to context store