xml.go 564 B

123456789101112131415161718192021222324252627
  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. "encoding/xml"
  7. "net/http"
  8. )
  9. type xmlBinding struct{}
  10. func (_ xmlBinding) Name() string {
  11. return "xml"
  12. }
  13. func (_ xmlBinding) Bind(req *http.Request, obj interface{}) error {
  14. decoder := xml.NewDecoder(req.Body)
  15. if err := decoder.Decode(obj); err != nil {
  16. return err
  17. }
  18. if err := _validator.ValidateStruct(obj); err != nil {
  19. return error(err)
  20. }
  21. return nil
  22. }