Use an approach to build stanza that do not require a "builder" abstraction

This commit is contained in:
Mickael Remond
2019-06-27 14:30:23 +02:00
parent 1dacc663d3
commit 20a66dc47d
7 changed files with 159 additions and 100 deletions
+13 -2
View File
@@ -10,6 +10,15 @@ import (
// marshal / unmarshal. There is no need to manage them on the manually
// crafted structure.
func xmlEqual(x, y interface{}) bool {
return cmp.Equal(x, y, xmlOpts())
}
// xmlDiff compares xml structures ignoring namespace preferences
func xmlDiff(x, y interface{}) string {
return cmp.Diff(x, y, xmlOpts())
}
func xmlOpts() cmp.Options {
alwaysEqual := cmp.Comparer(func(_, _ interface{}) bool { return true })
opts := cmp.Options{
cmp.FilterValues(func(x, y interface{}) bool {
@@ -20,10 +29,12 @@ func xmlEqual(x, y interface{}) bool {
if xx == zero || yy == zero {
return true
}
if xx.Space == "" || yy.Space == "" {
return true
}
}
return false
}, alwaysEqual),
}
return cmp.Equal(x, y, opts)
return opts
}