internal: fix XML element struct naming

We were sometimes using TitleCase, sometimes Lowercase. Let's align
on the idiomatic Go naming and pick TitleCase everywhere.
This commit is contained in:
Simon Ser
2022-05-31 17:32:12 +02:00
parent 55a9274ba6
commit d7891ce50c
10 changed files with 108 additions and 108 deletions

View File

@@ -111,7 +111,7 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
return resp, nil
}
func (c *Client) DoMultiStatus(req *http.Request) (*Multistatus, error) {
func (c *Client) DoMultiStatus(req *http.Request) (*MultiStatus, error) {
resp, err := c.Do(req)
if err != nil {
return nil, err
@@ -123,7 +123,7 @@ func (c *Client) DoMultiStatus(req *http.Request) (*Multistatus, error) {
}
// TODO: the response can be quite large, support streaming Response elements
var ms Multistatus
var ms MultiStatus
if err := xml.NewDecoder(resp.Body).Decode(&ms); err != nil {
return nil, err
}
@@ -131,7 +131,7 @@ func (c *Client) DoMultiStatus(req *http.Request) (*Multistatus, error) {
return &ms, nil
}
func (c *Client) Propfind(path string, depth Depth, propfind *Propfind) (*Multistatus, error) {
func (c *Client) PropFind(path string, depth Depth, propfind *PropFind) (*MultiStatus, error) {
req, err := c.NewXMLRequest("PROPFIND", path, propfind)
if err != nil {
return nil, err
@@ -143,8 +143,8 @@ func (c *Client) Propfind(path string, depth Depth, propfind *Propfind) (*Multis
}
// PropfindFlat performs a PROPFIND request with a zero depth.
func (c *Client) PropfindFlat(path string, propfind *Propfind) (*Response, error) {
ms, err := c.Propfind(path, DepthZero, propfind)
func (c *Client) PropFindFlat(path string, propfind *PropFind) (*Response, error) {
ms, err := c.PropFind(path, DepthZero, propfind)
if err != nil {
return nil, err
}
@@ -196,7 +196,7 @@ func (c *Client) Options(path string) (classes map[string]bool, methods map[stri
}
// SyncCollection perform a `sync-collection` REPORT operation on a resource
func (c *Client) SyncCollection(path, syncToken string, level Depth, limit *Limit, prop *Prop) (*Multistatus, error) {
func (c *Client) SyncCollection(path, syncToken string, level Depth, limit *Limit, prop *Prop) (*MultiStatus, error) {
q := SyncCollectionQuery{
SyncToken: syncToken,
SyncLevel: level.String(),

View File

@@ -89,22 +89,22 @@ func (h *Href) UnmarshalText(b []byte) error {
}
// https://tools.ietf.org/html/rfc4918#section-14.16
type Multistatus struct {
type MultiStatus struct {
XMLName xml.Name `xml:"DAV: multistatus"`
Responses []Response `xml:"response"`
ResponseDescription string `xml:"responsedescription,omitempty"`
SyncToken string `xml:"sync-token,omitempty"`
}
func NewMultistatus(resps ...Response) *Multistatus {
return &Multistatus{Responses: resps}
func NewMultiStatus(resps ...Response) *MultiStatus {
return &MultiStatus{Responses: resps}
}
// https://tools.ietf.org/html/rfc4918#section-14.24
type Response struct {
XMLName xml.Name `xml:"DAV: response"`
Hrefs []Href `xml:"href"`
Propstats []Propstat `xml:"propstat,omitempty"`
PropStats []PropStat `xml:"propstat,omitempty"`
ResponseDescription string `xml:"responsedescription,omitempty"`
Status *Status `xml:"status,omitempty"`
Error *Error `xml:"error,omitempty"`
@@ -179,7 +179,7 @@ func (resp *Response) DecodeProp(values ...interface{}) error {
if err := resp.Err(); err != nil {
return newPropError(name, err)
}
for _, propstat := range resp.Propstats {
for _, propstat := range resp.PropStats {
raw := propstat.Prop.Get(name)
if raw == nil {
continue
@@ -211,15 +211,15 @@ func (resp *Response) EncodeProp(code int, v interface{}) error {
return err
}
for i := range resp.Propstats {
propstat := &resp.Propstats[i]
for i := range resp.PropStats {
propstat := &resp.PropStats[i]
if propstat.Status.Code == code {
propstat.Prop.Raw = append(propstat.Prop.Raw, *raw)
return nil
}
}
resp.Propstats = append(resp.Propstats, Propstat{
resp.PropStats = append(resp.PropStats, PropStat{
Status: Status{Code: code},
Prop: Prop{Raw: []RawXMLValue{*raw}},
})
@@ -233,7 +233,7 @@ type Location struct {
}
// https://tools.ietf.org/html/rfc4918#section-14.22
type Propstat struct {
type PropStat struct {
XMLName xml.Name `xml:"DAV: propstat"`
Prop Prop `xml:"prop"`
Status Status `xml:"status"`
@@ -284,7 +284,7 @@ func (p *Prop) Decode(v interface{}) error {
}
// https://tools.ietf.org/html/rfc4918#section-14.20
type Propfind struct {
type PropFind struct {
XMLName xml.Name `xml:"DAV: propfind"`
Prop *Prop `xml:"prop,omitempty"`
AllProp *struct{} `xml:"allprop,omitempty"`
@@ -300,8 +300,8 @@ func xmlNamesToRaw(names []xml.Name) []RawXMLValue {
return l
}
func NewPropNamePropfind(names ...xml.Name) *Propfind {
return &Propfind{Prop: &Prop{Raw: xmlNamesToRaw(names)}}
func NewPropNamePropFind(names ...xml.Name) *PropFind {
return &PropFind{Prop: &Prop{Raw: xmlNamesToRaw(names)}}
}
// https://tools.ietf.org/html/rfc4918#section-14.8
@@ -329,7 +329,7 @@ func (t *ResourceType) Is(name xml.Name) bool {
return false
}
var CollectionName = xml.Name{"DAV:", "collection"}
var CollectionName = xml.Name{Namespace, "collection"}
// https://tools.ietf.org/html/rfc4918#section-15.4
type GetContentLength struct {
@@ -415,7 +415,7 @@ type CurrentUserPrincipal struct {
}
// https://tools.ietf.org/html/rfc4918#section-14.19
type Propertyupdate struct {
type PropertyUpdate struct {
XMLName xml.Name `xml:"DAV: propertyupdate"`
Remove []Remove `xml:"remove"`
Set []Set `xml:"set"`

View File

@@ -20,7 +20,7 @@ const exampleDeleteMultistatusStr = `<?xml version="1.0" encoding="utf-8" ?>
func TestResponse_Err_error(t *testing.T) {
r := strings.NewReader(exampleDeleteMultistatusStr)
var ms Multistatus
var ms MultiStatus
if err := xml.NewDecoder(r).Decode(&ms); err != nil {
t.Fatalf("Decode() = %v", err)
}

View File

@@ -45,7 +45,7 @@ func ServeXML(w http.ResponseWriter) *xml.Encoder {
return xml.NewEncoder(w)
}
func ServeMultistatus(w http.ResponseWriter, ms *Multistatus) error {
func ServeMultiStatus(w http.ResponseWriter, ms *MultiStatus) error {
// TODO: streaming
w.WriteHeader(http.StatusMultiStatus)
return ServeXML(w).Encode(ms)
@@ -54,8 +54,8 @@ func ServeMultistatus(w http.ResponseWriter, ms *Multistatus) error {
type Backend interface {
Options(r *http.Request) (caps []string, allow []string, err error)
HeadGet(w http.ResponseWriter, r *http.Request) error
Propfind(r *http.Request, pf *Propfind, depth Depth) (*Multistatus, error)
Proppatch(r *http.Request, pu *Propertyupdate) (*Response, error)
PropFind(r *http.Request, pf *PropFind, depth Depth) (*MultiStatus, error)
PropPatch(r *http.Request, pu *PropertyUpdate) (*Response, error)
Put(r *http.Request) (*Href, error)
Delete(r *http.Request) error
Mkcol(r *http.Request) error
@@ -130,7 +130,7 @@ func (h *Handler) handleOptions(w http.ResponseWriter, r *http.Request) error {
}
func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) error {
var propfind Propfind
var propfind PropFind
if err := DecodeXMLRequest(r, &propfind); err != nil {
return err
}
@@ -144,17 +144,17 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) error {
}
}
ms, err := h.Backend.Propfind(r, &propfind, depth)
ms, err := h.Backend.PropFind(r, &propfind, depth)
if err != nil {
return err
}
return ServeMultistatus(w, ms)
return ServeMultiStatus(w, ms)
}
type PropfindFunc func(raw *RawXMLValue) (interface{}, error)
type PropFindFunc func(raw *RawXMLValue) (interface{}, error)
func NewPropfindResponse(path string, propfind *Propfind, props map[xml.Name]PropfindFunc) (*Response, error) {
func NewPropFindResponse(path string, propfind *PropFind, props map[xml.Name]PropFindFunc) (*Response, error) {
resp := NewOKResponse(path)
if _, ok := props[ResourceTypeName]; !ok {
@@ -224,18 +224,18 @@ func NewPropfindResponse(path string, propfind *Propfind, props map[xml.Name]Pro
}
func (h *Handler) handleProppatch(w http.ResponseWriter, r *http.Request) error {
var update Propertyupdate
var update PropertyUpdate
if err := DecodeXMLRequest(r, &update); err != nil {
return err
}
resp, err := h.Backend.Proppatch(r, &update)
resp, err := h.Backend.PropPatch(r, &update)
if err != nil {
return err
}
ms := NewMultistatus(*resp)
return ServeMultistatus(w, ms)
ms := NewMultiStatus(*resp)
return ServeMultiStatus(w, ms)
}
func parseDestination(h http.Header) (*Href, error) {