internal: allow Response.DecodeProp to decode multiple values

This commit is contained in:
Simon Ser 2020-01-21 18:41:25 +01:00
parent 3e41eefd12
commit 63cdea07be
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -131,26 +131,30 @@ func IsMissingProp(err error) bool {
return ok return ok
} }
func (resp *Response) DecodeProp(v interface{}) error { func (resp *Response) DecodeProp(values ...interface{}) error {
// TODO wrap errors with more context (XML name) for _, v := range values {
name, err := valueXMLName(v) // TODO wrap errors with more context (XML name)
if err != nil { name, err := valueXMLName(v)
return err if err != nil {
}
if err := resp.Status.Err(); err != nil {
return err
}
for _, propstat := range resp.Propstats {
raw := propstat.Prop.Get(name)
if raw == nil {
continue
}
if err := propstat.Status.Err(); err != nil {
return err return err
} }
return raw.Decode(v) if err := resp.Status.Err(); err != nil {
return err
}
for _, propstat := range resp.Propstats {
raw := propstat.Prop.Get(name)
if raw == nil {
continue
}
if err := propstat.Status.Err(); err != nil {
return err
}
return raw.Decode(v)
}
return &missingPropError{name}
} }
return &missingPropError{name}
return nil
} }
func (resp *Response) EncodeProp(code int, v interface{}) error { func (resp *Response) EncodeProp(code int, v interface{}) error {