xml.go 367 B

12345678910111213141516171819202122
  1. package binding
  2. import (
  3. "encoding/xml"
  4. "net/http"
  5. "github.com/pkg/errors"
  6. )
  7. type xmlBinding struct{}
  8. func (xmlBinding) Name() string {
  9. return "xml"
  10. }
  11. func (xmlBinding) Bind(req *http.Request, obj interface{}) error {
  12. decoder := xml.NewDecoder(req.Body)
  13. if err := decoder.Decode(obj); err != nil {
  14. return errors.WithStack(err)
  15. }
  16. return validate(obj)
  17. }