Skip to content

Commit

Permalink
reduce unnecessary use of pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Apr 4, 2022
1 parent 9c8dd92 commit 9f90ce1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
12 changes: 6 additions & 6 deletions internal/http/services/owncloud/ocdav/propfind/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ type PropstatXML struct {
// not honoring namespace declarations inside a xmltag with a
// parent element for anonymous slice elements.
// Use of multistatusWriter takes care of this.
Prop []*props.PropertyXML `xml:"d:prop>_ignored_"`
Status string `xml:"d:status"`
Error *errors.ErrorXML `xml:"d:error"`
ResponseDescription string `xml:"d:responsedescription,omitempty"`
Prop []props.PropertyXML `xml:"d:prop>_ignored_"`
Status string `xml:"d:status"`
Error *errors.ErrorXML `xml:"d:error"`
ResponseDescription string `xml:"d:responsedescription,omitempty"`
}

// ResponseXML holds the xml representation of a propfind response
Expand Down Expand Up @@ -728,11 +728,11 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p

propstatOK := PropstatXML{
Status: "HTTP/1.1 200 OK",
Prop: []*props.PropertyXML{},
Prop: []props.PropertyXML{},
}
propstatNotFound := PropstatXML{
Status: "HTTP/1.1 404 Not Found",
Prop: []*props.PropertyXML{},
Prop: []props.PropertyXML{},
}
// when allprops has been requested
if pf.Allprop != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/http/services/owncloud/ocdav/proppatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (s *svc) formatProppatchResponse(ctx context.Context, acceptedProps []xml.N
}

if len(acceptedProps) > 0 {
propstatBody := []*props.PropertyXML{}
propstatBody := []props.PropertyXML{}
for i := range acceptedProps {
propstatBody = append(propstatBody, props.NewPropNS(acceptedProps[i].Space, acceptedProps[i].Local, ""))
}
Expand All @@ -334,7 +334,7 @@ func (s *svc) formatProppatchResponse(ctx context.Context, acceptedProps []xml.N
}

if len(removedProps) > 0 {
propstatBody := []*props.PropertyXML{}
propstatBody := []props.PropertyXML{}
for i := range removedProps {
propstatBody = append(propstatBody, props.NewPropNS(removedProps[i].Space, removedProps[i].Local, ""))
}
Expand Down
20 changes: 10 additions & 10 deletions internal/http/services/owncloud/ocdav/props/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func xmlEscaped(val string) []byte {
}

// NewPropNS returns a new PropertyXML instance
func NewPropNS(namespace string, local string, val string) *PropertyXML {
return &PropertyXML{
func NewPropNS(namespace string, local string, val string) PropertyXML {
return PropertyXML{
XMLName: xml.Name{Space: namespace, Local: local},
Lang: "",
InnerXML: xmlEscaped(val),
Expand All @@ -60,34 +60,34 @@ func NewPropNS(namespace string, local string, val string) *PropertyXML {

// NewProp returns a new PropertyXML instance while xml-escaping the value
// TODO properly use the space
func NewProp(key, val string) *PropertyXML {
return &PropertyXML{
func NewProp(key, val string) PropertyXML {
return PropertyXML{
XMLName: xml.Name{Space: "", Local: key},
Lang: "",
InnerXML: xmlEscaped(val),
}
}

// NewNotFound returns a new PropertyXML instance with an empty value
func NewNotFound(key string) *PropertyXML {
return &PropertyXML{
func NewNotFound(key string) PropertyXML {
return PropertyXML{
XMLName: xml.Name{Space: "", Local: key},
Lang: "",
}
}

// NewNotFound returns a new PropertyXML instance with the given namespace and an empty value
func NewNotFoundNS(namespace, key string) *PropertyXML {
return &PropertyXML{
func NewNotFoundNS(namespace, key string) PropertyXML {
return PropertyXML{
XMLName: xml.Name{Space: namespace, Local: key},
Lang: "",
}
}

// NewPropRaw returns a new PropertyXML instance for the given key/value pair
// TODO properly use the space
func NewPropRaw(key, val string) *PropertyXML {
return &PropertyXML{
func NewPropRaw(key, val string) PropertyXML {
return PropertyXML{
XMLName: xml.Name{Space: "", Local: key},
Lang: "",
InnerXML: []byte(val),
Expand Down
10 changes: 5 additions & 5 deletions internal/http/services/owncloud/ocdav/trashbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ func (h *TrashbinHandler) formatTrashPropfind(ctx context.Context, s *svc, space
Propstat: []propfind.PropstatXML{
{
Status: "HTTP/1.1 200 OK",
Prop: []*props.PropertyXML{
Prop: []props.PropertyXML{
props.NewPropRaw("d:resourcetype", "<d:collection/>"),
},
},
{
Status: "HTTP/1.1 404 Not Found",
Prop: []*props.PropertyXML{
Prop: []props.PropertyXML{
props.NewNotFound("oc:trashbin-original-filename"),
props.NewNotFound("oc:trashbin-original-location"),
props.NewNotFound("oc:trashbin-delete-datetime"),
Expand Down Expand Up @@ -362,7 +362,7 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, spaceI
// return all known properties
propstatOK := propfind.PropstatXML{
Status: "HTTP/1.1 200 OK",
Prop: []*props.PropertyXML{},
Prop: []props.PropertyXML{},
}
// yes this is redundant, can be derived from oc:trashbin-original-location which contains the full path, clients should not fetch it
propstatOK.Prop = append(propstatOK.Prop, props.NewProp("oc:trashbin-original-filename", path.Base(item.Ref.Path)))
Expand All @@ -384,11 +384,11 @@ func (h *TrashbinHandler) itemToPropResponse(ctx context.Context, s *svc, spaceI
// otherwise return only the requested properties
propstatOK := propfind.PropstatXML{
Status: "HTTP/1.1 200 OK",
Prop: []*props.PropertyXML{},
Prop: []props.PropertyXML{},
}
propstatNotFound := propfind.PropstatXML{
Status: "HTTP/1.1 404 Not Found",
Prop: []*props.PropertyXML{},
Prop: []props.PropertyXML{},
}
for i := range pf.Prop {
switch pf.Prop[i].Space {
Expand Down

0 comments on commit 9f90ce1

Please sign in to comment.