- With issues:
- Use the search tool before opening a new issue.
- Please provide source code and commit sha if you found a bug.
- Review existing issues and provide feedback or react to them.
Description
ShouldBindJSON
return EOF
when the request body is an empty string.
This error message is not friendly.
How to reproduce
package main
import (
"fmt"
"github.com/gin-gonic/gin"
)
type R struct {
C string `form:"c" binding:"required"`
}
func main() {
g := gin.Default()
g.POST("/hello", func(c *gin.Context) {
if err := c.BindJSON(&R{}); err != nil {
fmt.Println(err, len(c.Errors))
}
})
g.Run(":9000")
}
Expectations
$ curl --request POST '127.0.0.1:9000/hello' --data ''
Actual result
print EOF 1.
Expect:
`Key: 'R.C' Error:Field validation for 'C' failed on the 'required' tag 0` or `invalid request` or `empty body`
Environment
- go version:
- gin version (or commit ref):
- operating system: