-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
BindJSON returns EOF #439
Comments
Can you provide an example of the JSON you're using? |
Using the latest version of Gin I sometimes Get EOF error too while doing Struct that I am using: type LocationRequest struct {
RestaurantId uint `json:"restaurantId"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Reference string `json:"reference"`
} |
Same problem here! |
Without further details it's hard to reproduce such an issue, for my cases it works totally fine. |
Hello, i had this issue too, the problem occurs when i read from the Request Body twice. |
Hi all, it's just need to comment the code in BindWith method of context.go file, then it will not show two or more errors json structs , you can handle the error response on your side. |
Hi all, I just realized that when I validate JSON using Can you try validate your JSON first are they valid or not? for @vjeantet issue, read request body ( Please CMIIW, I'm quite new at Golang 😄 |
Same problem. it will happened when I use Decoder.Decode after ctx.Bind. Guess it's because of the former function will mark a terminated sign to the Context or something like that, so the second function returns EOF. How can I receive the other parameter that do not exist at the parameter struct if I can only read context once? I'm a green hand of golang, this question confused me a lot. |
same issue, then find the reason, I have a ioutils read |
The BindJSON is reading the body, so we are at EOF if the context Body get read multiple times. What would be the best approach? Storing it somewhere? |
@yunfengsay https://stackoverflow.com/questions/978061/http-get-with-request-body
|
I had this issue too, the problem occurs when i read from the Request Body twice. |
I have this issue too when I read from the request body more than once. |
Hi, all, please use |
Cloning the context is work for me
|
I guess you requestBody maybe not JSON, so you get EOF error.
|
|
json := make(map[string]interface{})
c.BindJSON(&json)
bodyStr, _ := jsoniter.MarshalToString(json) |
This is the right answer, my middleware that prints the request body was causing the problem, seems foolish but it's true lol |
I encountered a similar situation of
Gin's
Is there a better alternative (if any) than what I am doing? |
this issue occurs when you read body data twice.
|
I am trying to use context#BindJSON but it returns EOF. If I replace it with a JSON Decoder it works fine.
A sample of the code:
http://hastebin.com/torosarosi.go
Anyone know as to why it may be returning EOF?
The text was updated successfully, but these errors were encountered: