@@ -34,9 +34,9 @@ func (b *binder) Bind(i interface{}, ctx Context) (err error) {
3434 err = errors .New ("request unsupported MediaType -> " + ctype )
3535 switch {
3636 case strings .HasPrefix (ctype , MIMEApplicationJSON ):
37- err = json .NewDecoder ( req . Body ). Decode ( i )
37+ err = json .Unmarshal ( ctx . Request (). PostBody (), i )
3838 case strings .HasPrefix (ctype , MIMEApplicationXML ):
39- err = xml .NewDecoder ( req . Body ). Decode ( i )
39+ err = xml .Unmarshal ( ctx . Request (). PostBody (), i )
4040 //case strings.HasPrefix(ctype, MIMEApplicationForm), strings.HasPrefix(ctype, MIMEMultipartForm),
4141 // strings.HasPrefix(ctype, MIMETextHTML):
4242 // err = reflects.ConvertMapToStruct(defaultTagName, i, ctx.FormValues())
@@ -54,12 +54,11 @@ func (b *binder) Bind(i interface{}, ctx Context) (err error) {
5454
5555//BindJsonBody default use json decode req.Body to struct
5656func (b * binder ) BindJsonBody (i interface {}, ctx Context ) (err error ) {
57- req := ctx .Request ()
58- if req .Body == nil {
57+ if ctx .Request ().PostBody () == nil {
5958 err = errors .New ("request body can't be empty" )
6059 return err
6160 }
62- err = json .NewDecoder ( req . Body ). Decode ( i )
61+ err = json .Unmarshal ( ctx . Request (). PostBody (), i )
6362 return err
6463}
6564
0 commit comments