fix: check obj type in protobufBinding

This commit is contained in:
Tevic 2021-08-31 21:05:04 +08:00
parent 30cdbfcf4c
commit f21906a9b0

View File

@ -5,6 +5,7 @@
package binding package binding
import ( import (
"errors"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -26,7 +27,11 @@ func (b protobufBinding) Bind(req *http.Request, obj interface{}) error {
} }
func (protobufBinding) BindBody(body []byte, obj interface{}) error { func (protobufBinding) BindBody(body []byte, obj interface{}) error {
if err := proto.Unmarshal(body, obj.(proto.Message)); err != nil { msg, ok := obj.(proto.Message)
if !ok {
return errors.New("obj is not ProtoMessage")
}
if err := proto.Unmarshal(body, msg); err != nil {
return err return err
} }
// Here it's same to return validate(obj), but util now we can't add // Here it's same to return validate(obj), but util now we can't add