summaryrefslogtreecommitdiff
path: root/vendor/github.com/gin-gonic/gin/binding/protobuf.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/gin-gonic/gin/binding/protobuf.go')
-rw-r--r--vendor/github.com/gin-gonic/gin/binding/protobuf.go15
1 files changed, 10 insertions, 5 deletions
diff --git a/vendor/github.com/gin-gonic/gin/binding/protobuf.go b/vendor/github.com/gin-gonic/gin/binding/protobuf.go
index f9ece928d..44f2fdb93 100644
--- a/vendor/github.com/gin-gonic/gin/binding/protobuf.go
+++ b/vendor/github.com/gin-gonic/gin/binding/protobuf.go
@@ -1,14 +1,15 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
+// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package binding
import (
+ "errors"
"io/ioutil"
"net/http"
- "github.com/golang/protobuf/proto"
+ "google.golang.org/protobuf/proto"
)
type protobufBinding struct{}
@@ -17,7 +18,7 @@ func (protobufBinding) Name() string {
return "protobuf"
}
-func (b protobufBinding) Bind(req *http.Request, obj interface{}) error {
+func (b protobufBinding) Bind(req *http.Request, obj any) error {
buf, err := ioutil.ReadAll(req.Body)
if err != nil {
return err
@@ -25,8 +26,12 @@ func (b protobufBinding) Bind(req *http.Request, obj interface{}) error {
return b.BindBody(buf, obj)
}
-func (protobufBinding) BindBody(body []byte, obj interface{}) error {
- if err := proto.Unmarshal(body, obj.(proto.Message)); err != nil {
+func (protobufBinding) BindBody(body []byte, obj any) error {
+ 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