-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
having trouble writing a customer logger middleware #782
Comments
UpdateIn my case the problem was caused by Original problemHave related issue In one of my PUT request I get The request object is: type RecommendationAddRequest struct {
Xyz string `json:"xyz" validate:"required,gte=6"`
} The binder is the default one: if err := c.Bind(reqObj); err != nil {
println("error is:", err.Error())
return false
} And it print out:
The request is: curl -X PUT \
https://domain.com/api/whatever \
-H 'authorization: Bearer some-string' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"xyz": "ssss"
}' Tried to switch to |
|
@vishr Isn't it possible to restore body content during the Bind or should I implement custom Binder for that purpose? For now I implemented body data restore like it is done in the Body Dump MW (and well, like in the Medium post), which makes me think that this should be handled in the MW? |
Description
I am trying to log some custom fields in my custom logger middleware. I took the code from middleware/logger.go and tried to modify it in my own repo. I am getting EOF after I do a c.Bind()
Expected behaviour
I am expecting it work normally
Actual behaviour
I get an EOF after I add the c.Bind()
Steps to reproduce
middleware/logger.go
Working code to debug
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) (err error) {
//Begin Custom Code
r1 := &Request{}
if err = c.Bind(&r1); err != nil {
fmt.Println(err)
return err
}
//End Custom code
req := c.Request()
res := c.Response()
start := time.Now()
if err = next(c); err != nil {
c.Error(err) //This is where I get an EOF. If I remove the custom code everything works perfectly
}
Am I doing something wrong?
Version/commit
The text was updated successfully, but these errors were encountered: