msgpack.go 531 B

123456789101112131415161718192021222324
  1. // Copyright 2017 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/ugorji/go/codec"
  8. )
  9. type msgpackBinding struct{}
  10. func (msgpackBinding) Name() string {
  11. return "msgpack"
  12. }
  13. func (msgpackBinding) Bind(req *http.Request, obj interface{}) error {
  14. if err := codec.NewDecoder(req.Body, new(codec.MsgpackHandle)).Decode(&obj); err != nil {
  15. return err
  16. }
  17. return validate(obj)
  18. }