Description
When I was using data binding, I found that the second time I fetched the value after ShouldBind, the value became EOF. I found that I could use ShouldBindBodyWith, but when using this method, I needed to use different Bindding depending on the Content-Type.when using different Bindding eg.
b := binding.Default(c.Request.Method, c.ContentType())
err := c.ShouldBindBodyWith(&body,b)
But binding.Default returns Binding. but the values returned are all implementations of BindingBody. if you use the return value of BindingBody,so that this function can be used.
How to reproduce
// fix return Binding change to BindingBody
func Default(method, contentType string) BindingBody {
if method == http.MethodGet {
return Form
}
switch contentType {
case MIMEJSON:
return JSON
case MIMEXML, MIMEXML2:
return XML
case MIMEPROTOBUF:
return ProtoBuf
case MIMEMSGPACK, MIMEMSGPACK2:
return MsgPack
case MIMEYAML:
return YAML
case MIMEMultipartPOSTForm:
return FormMultipart
default: // case MIMEPOSTForm:
return Form
}
}
b := binding.Default(c.Request.Method, c.ContentType())
err := c.ShouldBindBodyWith(&body,b)
Environment
- go version: go version go1.16.9 darwin/amd64
- gin version: 1.7.7
- operating system: Mac OS