Skip to content

Commit

Permalink
fix: check obj type in protobufBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
Tevic committed Aug 31, 2021
1 parent 30cdbfc commit f21906a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion binding/protobuf.go
Expand Up @@ -5,6 +5,7 @@
package binding

import (
"errors"
"io/ioutil"
"net/http"

Expand All @@ -26,7 +27,11 @@ func (b protobufBinding) Bind(req *http.Request, 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
}
// Here it's same to return validate(obj), but util now we can't add
Expand Down

0 comments on commit f21906a

Please sign in to comment.