handle nil body for JSON binding (#1638)

This commit is contained in:
mllu
2018-11-21 17:55:51 -08:00
committed by thinkerou
parent 521d06c81d
commit 64457fbca7
2 changed files with 11 additions and 0 deletions

View File

@ -6,6 +6,7 @@ package binding
import (
"bytes"
"fmt"
"io"
"net/http"
@ -24,6 +25,9 @@ func (jsonBinding) Name() string {
}
func (jsonBinding) Bind(req *http.Request, obj interface{}) error {
if req == nil || req.Body == nil {
return fmt.Errorf("invalid request")
}
return decodeJSON(req.Body, obj)
}