protobuf.go 791 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright 2014 Manu Martinez-Almeida. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package binding
  5. import (
  6. "net/http"
  7. //"github.com/golang/protobuf/proto"
  8. )
  9. type protobufBinding struct{}
  10. func (protobufBinding) Name() string {
  11. return "protobuf"
  12. }
  13. func (protobufBinding) Bind(req *http.Request, obj interface{}) error {
  14. /*
  15. buf, err := ioutil.ReadAll(req.Body)
  16. if err != nil {
  17. return err
  18. }
  19. if err = proto.Unmarshal(buf, obj.(proto.Message)); err != nil {
  20. return err
  21. }
  22. //Here it's same to return validate(obj), but util now we cann't add `binding:""` to the struct
  23. //which automatically generate by gen-proto
  24. //return nil
  25. return validate(obj)
  26. // */
  27. return validate(obj)
  28. }