internal: add EncodeProp

This allows to simplify carddav.QueryAddressBook's request marshaling.
This commit is contained in:
Simon Ser
2020-01-15 11:17:38 +01:00
parent 45cd1977d4
commit 25ab0b2076
3 changed files with 26 additions and 13 deletions

View File

@@ -114,6 +114,18 @@ type Prop struct {
Raw []RawXMLValue `xml:",any"`
}
func EncodeProp(values ...interface{}) (*Prop, error) {
l := make([]RawXMLValue, len(values))
for i, v := range values {
raw, err := EncodeRawXMLElement(v)
if err != nil {
return nil, err
}
l[i] = *raw
}
return &Prop{Raw: l}, nil
}
// https://tools.ietf.org/html/rfc4918#section-14.20
type Propfind struct {
XMLName xml.Name `xml:"DAV: propfind"`
@@ -121,7 +133,7 @@ type Propfind struct {
// TODO: propname | (allprop, include?)
}
func NewPropPropfind(names ...xml.Name) *Propfind {
func NewPropNamePropfind(names ...xml.Name) *Propfind {
children := make([]RawXMLValue, len(names))
for i, name := range names {
children[i] = *NewRawXMLElement(name, nil, nil)