add xml-roundtrip-validator

This commit is contained in:
holooooo
2021-05-24 14:45:44 +08:00
parent e8f3cfed88
commit 5f5afc111a
3 changed files with 9 additions and 0 deletions

View File

@@ -49,6 +49,7 @@ import (
"strings"
"time"
xrv "github.com/mattermost/xml-roundtrip-validator"
"gopkg.in/yaml.v2"
"github.com/beego/beego/v2/core/berror"
@@ -638,6 +639,10 @@ func (b *BeegoHTTPRequest) ToXML(v interface{}) error {
if err != nil {
return err
}
if err := xrv.Validate(bytes.NewReader(data)); err != nil {
panic(err)
}
return berror.Wrap(xml.Unmarshal(data, v),
UnmarshalXMLResponseToObjectFailed, "unmarshal xml body to object failed.")
}