internal: add RawXMLValue.Decode

This commit is contained in:
Simon Ser 2020-01-14 18:53:29 +01:00
parent 3beb076950
commit 6f9ff62747
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 5 additions and 2 deletions

View File

@ -1,7 +1,6 @@
package webdav
import (
"encoding/xml"
"fmt"
"net/http"
"strings"
@ -55,7 +54,7 @@ func (c *Client) FindCurrentUserPrincipal() (string, error) {
propstat := &resp.Propstats[0]
var prop currentUserPrincipalProp
if err := xml.NewTokenDecoder(propstat.Prop.TokenReader()).Decode(&prop); err != nil {
if err := propstat.Prop.Decode(&prop); err != nil {
return "", err
}

View File

@ -62,6 +62,10 @@ func (val *RawXMLValue) MarshalXML(e *xml.Encoder, start xml.StartElement) error
var _ xml.Marshaler = (*RawXMLValue)(nil)
var _ xml.Unmarshaler = (*RawXMLValue)(nil)
func (val *RawXMLValue) Decode(v interface{}) error {
return xml.NewTokenDecoder(val.TokenReader()).Decode(&v)
}
// TokenReader returns a stream of tokens for the XML value.
func (val *RawXMLValue) TokenReader() xml.TokenReader {
return &rawXMLValueReader{val: val}