mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
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:
parent
55a9274ba6
commit
d7891ce50c
@ -35,8 +35,8 @@ func NewClient(c webdav.HTTPClient, endpoint string) (*Client, error) {
|
||||
}
|
||||
|
||||
func (c *Client) FindCalendarHomeSet(principal string) (string, error) {
|
||||
propfind := internal.NewPropNamePropfind(calendarHomeSetName)
|
||||
resp, err := c.ic.PropfindFlat(principal, propfind)
|
||||
propfind := internal.NewPropNamePropFind(calendarHomeSetName)
|
||||
resp, err := c.ic.PropFindFlat(principal, propfind)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -50,14 +50,14 @@ func (c *Client) FindCalendarHomeSet(principal string) (string, error) {
|
||||
}
|
||||
|
||||
func (c *Client) FindCalendars(calendarHomeSet string) ([]Calendar, error) {
|
||||
propfind := internal.NewPropNamePropfind(
|
||||
propfind := internal.NewPropNamePropFind(
|
||||
internal.ResourceTypeName,
|
||||
internal.DisplayNameName,
|
||||
calendarDescriptionName,
|
||||
maxResourceSizeName,
|
||||
supportedCalendarComponentSetName,
|
||||
)
|
||||
ms, err := c.ic.Propfind(calendarHomeSet, internal.DepthOne, propfind)
|
||||
ms, err := c.ic.PropFind(calendarHomeSet, internal.DepthOne, propfind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -168,7 +168,7 @@ func encodeCompFilter(filter *CompFilter) *compFilter {
|
||||
return &encoded
|
||||
}
|
||||
|
||||
func decodeCalendarObjectList(ms *internal.Multistatus) ([]CalendarObject, error) {
|
||||
func decodeCalendarObjectList(ms *internal.MultiStatus) ([]CalendarObject, error) {
|
||||
addrs := make([]CalendarObject, 0, len(ms.Responses))
|
||||
for _, resp := range ms.Responses {
|
||||
path, err := resp.Path()
|
||||
|
@ -215,21 +215,21 @@ func (h *Handler) handleQuery(r *http.Request, w http.ResponseWriter, query *cal
|
||||
var resps []internal.Response
|
||||
for _, co := range cos {
|
||||
b := backend{h.Backend}
|
||||
propfind := internal.Propfind{
|
||||
propfind := internal.PropFind{
|
||||
Prop: query.Prop,
|
||||
AllProp: query.AllProp,
|
||||
PropName: query.PropName,
|
||||
}
|
||||
resp, err := b.propfindCalendarObject(r.Context(), &propfind, &co)
|
||||
resp, err := b.propFindCalendarObject(r.Context(), &propfind, &co)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resps = append(resps, *resp)
|
||||
}
|
||||
|
||||
ms := internal.NewMultistatus(resps...)
|
||||
ms := internal.NewMultiStatus(resps...)
|
||||
|
||||
return internal.ServeMultistatus(w, ms)
|
||||
return internal.ServeMultiStatus(w, ms)
|
||||
}
|
||||
|
||||
func (h *Handler) handleMultiget(ctx context.Context, w http.ResponseWriter, multiget *calendarMultiget) error {
|
||||
@ -256,20 +256,20 @@ func (h *Handler) handleMultiget(ctx context.Context, w http.ResponseWriter, mul
|
||||
}
|
||||
|
||||
b := backend{h.Backend}
|
||||
propfind := internal.Propfind{
|
||||
propfind := internal.PropFind{
|
||||
Prop: multiget.Prop,
|
||||
AllProp: multiget.AllProp,
|
||||
PropName: multiget.PropName,
|
||||
}
|
||||
resp, err := b.propfindCalendarObject(ctx, &propfind, co)
|
||||
resp, err := b.propFindCalendarObject(ctx, &propfind, co)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resps = append(resps, *resp)
|
||||
}
|
||||
|
||||
ms := internal.NewMultistatus(resps...)
|
||||
return internal.ServeMultistatus(w, ms)
|
||||
ms := internal.NewMultiStatus(resps...)
|
||||
return internal.ServeMultiStatus(w, ms)
|
||||
}
|
||||
|
||||
type backend struct {
|
||||
@ -338,7 +338,7 @@ func (b *backend) HeadGet(w http.ResponseWriter, r *http.Request) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth internal.Depth) (*internal.Multistatus, error) {
|
||||
func (b *backend) PropFind(r *http.Request, propfind *internal.PropFind, depth internal.Depth) (*internal.MultiStatus, error) {
|
||||
homeSetPath, err := b.Backend.CalendarHomeSetPath(r.Context())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -351,7 +351,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
var resps []internal.Response
|
||||
|
||||
if r.URL.Path == principalPath {
|
||||
resp, err := b.propfindUserPrincipal(r.Context(), propfind, homeSetPath)
|
||||
resp, err := b.propFindUserPrincipal(r.Context(), propfind, homeSetPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -362,7 +362,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := b.propfindCalendar(r.Context(), propfind, cal)
|
||||
resp, err := b.propFindCalendar(r.Context(), propfind, cal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -375,16 +375,16 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
// TODO
|
||||
}
|
||||
|
||||
return internal.NewMultistatus(resps...), nil
|
||||
return internal.NewMultiStatus(resps...), nil
|
||||
}
|
||||
|
||||
func (b *backend) propfindUserPrincipal(ctx context.Context, propfind *internal.Propfind, homeSetPath string) (*internal.Response, error) {
|
||||
func (b *backend) propFindUserPrincipal(ctx context.Context, propfind *internal.PropFind, homeSetPath string) (*internal.Response, error) {
|
||||
principalPath, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
props := map[xml.Name]internal.PropfindFunc{
|
||||
props := map[xml.Name]internal.PropFindFunc{
|
||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: principalPath}}, nil
|
||||
},
|
||||
@ -392,11 +392,11 @@ func (b *backend) propfindUserPrincipal(ctx context.Context, propfind *internal.
|
||||
return &calendarHomeSet{Href: internal.Href{Path: homeSetPath}}, nil
|
||||
},
|
||||
}
|
||||
return internal.NewPropfindResponse(principalPath, propfind, props)
|
||||
return internal.NewPropFindResponse(principalPath, propfind, props)
|
||||
}
|
||||
|
||||
func (b *backend) propfindCalendar(ctx context.Context, propfind *internal.Propfind, cal *Calendar) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropfindFunc{
|
||||
func (b *backend) propFindCalendar(ctx context.Context, propfind *internal.PropFind, cal *Calendar) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropFindFunc{
|
||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
path, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||
if err != nil {
|
||||
@ -443,11 +443,11 @@ func (b *backend) propfindCalendar(ctx context.Context, propfind *internal.Propf
|
||||
|
||||
// TODO: CALDAV:calendar-timezone, CALDAV:supported-calendar-component-set, CALDAV:min-date-time, CALDAV:max-date-time, CALDAV:max-instances, CALDAV:max-attendees-per-instance
|
||||
|
||||
return internal.NewPropfindResponse(cal.Path, propfind, props)
|
||||
return internal.NewPropFindResponse(cal.Path, propfind, props)
|
||||
}
|
||||
|
||||
func (b *backend) propfindCalendarObject(ctx context.Context, propfind *internal.Propfind, co *CalendarObject) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropfindFunc{
|
||||
func (b *backend) propFindCalendarObject(ctx context.Context, propfind *internal.PropFind, co *CalendarObject) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropFindFunc{
|
||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
path, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||
if err != nil {
|
||||
@ -486,10 +486,10 @@ func (b *backend) propfindCalendarObject(ctx context.Context, propfind *internal
|
||||
}
|
||||
}
|
||||
|
||||
return internal.NewPropfindResponse(co.Path, propfind, props)
|
||||
return internal.NewPropFindResponse(co.Path, propfind, props)
|
||||
}
|
||||
|
||||
func (b *backend) Proppatch(r *http.Request, update *internal.Propertyupdate) (*internal.Response, error) {
|
||||
func (b *backend) PropPatch(r *http.Request, update *internal.PropertyUpdate) (*internal.Response, error) {
|
||||
panic("TODO")
|
||||
}
|
||||
|
||||
|
@ -81,8 +81,8 @@ func (c *Client) HasSupport() error {
|
||||
}
|
||||
|
||||
func (c *Client) FindAddressBookHomeSet(principal string) (string, error) {
|
||||
propfind := internal.NewPropNamePropfind(addressBookHomeSetName)
|
||||
resp, err := c.ic.PropfindFlat(principal, propfind)
|
||||
propfind := internal.NewPropNamePropFind(addressBookHomeSetName)
|
||||
resp, err := c.ic.PropFindFlat(principal, propfind)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -104,14 +104,14 @@ func decodeSupportedAddressData(supported *supportedAddressData) []AddressDataTy
|
||||
}
|
||||
|
||||
func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, error) {
|
||||
propfind := internal.NewPropNamePropfind(
|
||||
propfind := internal.NewPropNamePropFind(
|
||||
internal.ResourceTypeName,
|
||||
internal.DisplayNameName,
|
||||
addressBookDescriptionName,
|
||||
maxResourceSizeName,
|
||||
supportedAddressDataName,
|
||||
)
|
||||
ms, err := c.ic.Propfind(addressBookHomeSet, internal.DepthOne, propfind)
|
||||
ms, err := c.ic.PropFind(addressBookHomeSet, internal.DepthOne, propfind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -224,7 +224,7 @@ func encodeTextMatch(tm *TextMatch) *textMatch {
|
||||
}
|
||||
}
|
||||
|
||||
func decodeAddressList(ms *internal.Multistatus) ([]AddressObject, error) {
|
||||
func decodeAddressList(ms *internal.MultiStatus) ([]AddressObject, error) {
|
||||
addrs := make([]AddressObject, 0, len(ms.Responses))
|
||||
for _, resp := range ms.Responses {
|
||||
path, err := resp.Path()
|
||||
|
@ -170,7 +170,7 @@ func (h *Handler) handleQuery(ctx context.Context, w http.ResponseWriter, query
|
||||
if query.Limit != nil {
|
||||
q.Limit = int(query.Limit.NResults)
|
||||
if q.Limit <= 0 {
|
||||
return internal.ServeMultistatus(w, internal.NewMultistatus())
|
||||
return internal.ServeMultiStatus(w, internal.NewMultiStatus())
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,20 +182,20 @@ func (h *Handler) handleQuery(ctx context.Context, w http.ResponseWriter, query
|
||||
var resps []internal.Response
|
||||
for _, ao := range aos {
|
||||
b := backend{h.Backend}
|
||||
propfind := internal.Propfind{
|
||||
propfind := internal.PropFind{
|
||||
Prop: query.Prop,
|
||||
AllProp: query.AllProp,
|
||||
PropName: query.PropName,
|
||||
}
|
||||
resp, err := b.propfindAddressObject(ctx, &propfind, &ao)
|
||||
resp, err := b.propFindAddressObject(ctx, &propfind, &ao)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resps = append(resps, *resp)
|
||||
}
|
||||
|
||||
ms := internal.NewMultistatus(resps...)
|
||||
return internal.ServeMultistatus(w, ms)
|
||||
ms := internal.NewMultiStatus(resps...)
|
||||
return internal.ServeMultiStatus(w, ms)
|
||||
}
|
||||
|
||||
func (h *Handler) handleMultiget(ctx context.Context, w http.ResponseWriter, multiget *addressbookMultiget) error {
|
||||
@ -222,20 +222,20 @@ func (h *Handler) handleMultiget(ctx context.Context, w http.ResponseWriter, mul
|
||||
}
|
||||
|
||||
b := backend{h.Backend}
|
||||
propfind := internal.Propfind{
|
||||
propfind := internal.PropFind{
|
||||
Prop: multiget.Prop,
|
||||
AllProp: multiget.AllProp,
|
||||
PropName: multiget.PropName,
|
||||
}
|
||||
resp, err := b.propfindAddressObject(ctx, &propfind, ao)
|
||||
resp, err := b.propFindAddressObject(ctx, &propfind, ao)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resps = append(resps, *resp)
|
||||
}
|
||||
|
||||
ms := internal.NewMultistatus(resps...)
|
||||
return internal.ServeMultistatus(w, ms)
|
||||
ms := internal.NewMultiStatus(resps...)
|
||||
return internal.ServeMultiStatus(w, ms)
|
||||
}
|
||||
|
||||
type backend struct {
|
||||
@ -306,7 +306,7 @@ func (b *backend) HeadGet(w http.ResponseWriter, r *http.Request) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth internal.Depth) (*internal.Multistatus, error) {
|
||||
func (b *backend) PropFind(r *http.Request, propfind *internal.PropFind, depth internal.Depth) (*internal.MultiStatus, error) {
|
||||
homeSetPath, err := b.Backend.AddressbookHomeSetPath(r.Context())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -321,7 +321,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
var resps []internal.Response
|
||||
|
||||
if r.URL.Path == principalPath {
|
||||
resp, err := b.propfindUserPrincipal(r.Context(), propfind, homeSetPath)
|
||||
resp, err := b.propFindUserPrincipal(r.Context(), propfind, homeSetPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -332,7 +332,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := b.propfindAddressBook(r.Context(), propfind, ab)
|
||||
resp, err := b.propFindAddressBook(r.Context(), propfind, ab)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -345,7 +345,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
}
|
||||
|
||||
for _, ao := range aos {
|
||||
resp, err := b.propfindAddressObject(r.Context(), propfind, &ao)
|
||||
resp, err := b.propFindAddressObject(r.Context(), propfind, &ao)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -358,23 +358,23 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := b.propfindAddressObject(r.Context(), propfind, ao)
|
||||
resp, err := b.propFindAddressObject(r.Context(), propfind, ao)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resps = append(resps, *resp)
|
||||
}
|
||||
|
||||
return internal.NewMultistatus(resps...), nil
|
||||
return internal.NewMultiStatus(resps...), nil
|
||||
}
|
||||
|
||||
func (b *backend) propfindUserPrincipal(ctx context.Context, propfind *internal.Propfind, homeSetPath string) (*internal.Response, error) {
|
||||
func (b *backend) propFindUserPrincipal(ctx context.Context, propfind *internal.PropFind, homeSetPath string) (*internal.Response, error) {
|
||||
principalPath, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
props := map[xml.Name]internal.PropfindFunc{
|
||||
props := map[xml.Name]internal.PropFindFunc{
|
||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
return &internal.CurrentUserPrincipal{Href: internal.Href{Path: principalPath}}, nil
|
||||
},
|
||||
@ -382,11 +382,11 @@ func (b *backend) propfindUserPrincipal(ctx context.Context, propfind *internal.
|
||||
return &addressbookHomeSet{Href: internal.Href{Path: homeSetPath}}, nil
|
||||
},
|
||||
}
|
||||
return internal.NewPropfindResponse(principalPath, propfind, props)
|
||||
return internal.NewPropFindResponse(principalPath, propfind, props)
|
||||
}
|
||||
|
||||
func (b *backend) propfindAddressBook(ctx context.Context, propfind *internal.Propfind, ab *AddressBook) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropfindFunc{
|
||||
func (b *backend) propFindAddressBook(ctx context.Context, propfind *internal.PropFind, ab *AddressBook) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropFindFunc{
|
||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
path, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||
if err != nil {
|
||||
@ -419,11 +419,11 @@ func (b *backend) propfindAddressBook(ctx context.Context, propfind *internal.Pr
|
||||
}
|
||||
}
|
||||
|
||||
return internal.NewPropfindResponse(ab.Path, propfind, props)
|
||||
return internal.NewPropFindResponse(ab.Path, propfind, props)
|
||||
}
|
||||
|
||||
func (b *backend) propfindAddressObject(ctx context.Context, propfind *internal.Propfind, ao *AddressObject) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropfindFunc{
|
||||
func (b *backend) propFindAddressObject(ctx context.Context, propfind *internal.PropFind, ao *AddressObject) (*internal.Response, error) {
|
||||
props := map[xml.Name]internal.PropFindFunc{
|
||||
internal.CurrentUserPrincipalName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
path, err := b.Backend.CurrentUserPrincipal(ctx)
|
||||
if err != nil {
|
||||
@ -462,10 +462,10 @@ func (b *backend) propfindAddressObject(ctx context.Context, propfind *internal.
|
||||
}
|
||||
}
|
||||
|
||||
return internal.NewPropfindResponse(ao.Path, propfind, props)
|
||||
return internal.NewPropFindResponse(ao.Path, propfind, props)
|
||||
}
|
||||
|
||||
func (b *backend) Proppatch(r *http.Request, update *internal.Propertyupdate) (*internal.Response, error) {
|
||||
func (b *backend) PropPatch(r *http.Request, update *internal.PropertyUpdate) (*internal.Response, error) {
|
||||
homeSetPath, err := b.Backend.AddressbookHomeSetPath(r.Context())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
10
client.go
10
client.go
@ -48,11 +48,11 @@ func NewClient(c HTTPClient, endpoint string) (*Client, error) {
|
||||
}
|
||||
|
||||
func (c *Client) FindCurrentUserPrincipal() (string, error) {
|
||||
propfind := internal.NewPropNamePropfind(internal.CurrentUserPrincipalName)
|
||||
propfind := internal.NewPropNamePropFind(internal.CurrentUserPrincipalName)
|
||||
|
||||
// TODO: consider retrying on the root URI "/" if this fails, as suggested
|
||||
// by the RFC?
|
||||
resp, err := c.ic.PropfindFlat("", propfind)
|
||||
resp, err := c.ic.PropFindFlat("", propfind)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -68,7 +68,7 @@ func (c *Client) FindCurrentUserPrincipal() (string, error) {
|
||||
return prop.Href.Path, nil
|
||||
}
|
||||
|
||||
var fileInfoPropfind = internal.NewPropNamePropfind(
|
||||
var fileInfoPropFind = internal.NewPropNamePropFind(
|
||||
internal.ResourceTypeName,
|
||||
internal.GetContentLengthName,
|
||||
internal.GetLastModifiedName,
|
||||
@ -122,7 +122,7 @@ func fileInfoFromResponse(resp *internal.Response) (*FileInfo, error) {
|
||||
}
|
||||
|
||||
func (c *Client) Stat(name string) (*FileInfo, error) {
|
||||
resp, err := c.ic.PropfindFlat(name, fileInfoPropfind)
|
||||
resp, err := c.ic.PropFindFlat(name, fileInfoPropFind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -149,7 +149,7 @@ func (c *Client) Readdir(name string, recursive bool) ([]FileInfo, error) {
|
||||
depth = internal.DepthInfinity
|
||||
}
|
||||
|
||||
ms, err := c.ic.Propfind(name, depth, fileInfoPropfind)
|
||||
ms, err := c.ic.PropFind(name, depth, fileInfoPropFind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -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(),
|
||||
|
@ -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"`
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
26
server.go
26
server.go
@ -117,7 +117,7 @@ func (b *backend) HeadGet(w http.ResponseWriter, r *http.Request) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth internal.Depth) (*internal.Multistatus, error) {
|
||||
func (b *backend) PropFind(r *http.Request, propfind *internal.PropFind, depth internal.Depth) (*internal.MultiStatus, error) {
|
||||
// TODO: use partial error Response on error
|
||||
|
||||
fi, err := b.FileSystem.Stat(r.URL.Path)
|
||||
@ -136,14 +136,14 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
|
||||
resps = make([]internal.Response, len(children))
|
||||
for i, child := range children {
|
||||
resp, err := b.propfindFile(propfind, &child)
|
||||
resp, err := b.propFindFile(propfind, &child)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resps[i] = *resp
|
||||
}
|
||||
} else {
|
||||
resp, err := b.propfindFile(propfind, fi)
|
||||
resp, err := b.propFindFile(propfind, fi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -151,11 +151,11 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
||||
resps = []internal.Response{*resp}
|
||||
}
|
||||
|
||||
return internal.NewMultistatus(resps...), nil
|
||||
return internal.NewMultiStatus(resps...), nil
|
||||
}
|
||||
|
||||
func (b *backend) propfindFile(propfind *internal.Propfind, fi *FileInfo) (*internal.Response, error) {
|
||||
props := make(map[xml.Name]internal.PropfindFunc)
|
||||
func (b *backend) propFindFile(propfind *internal.PropFind, fi *FileInfo) (*internal.Response, error) {
|
||||
props := make(map[xml.Name]internal.PropFindFunc)
|
||||
|
||||
props[internal.ResourceTypeName] = func(*internal.RawXMLValue) (interface{}, error) {
|
||||
var types []xml.Name
|
||||
@ -189,10 +189,10 @@ func (b *backend) propfindFile(propfind *internal.Propfind, fi *FileInfo) (*inte
|
||||
}
|
||||
}
|
||||
|
||||
return internal.NewPropfindResponse(fi.Path, propfind, props)
|
||||
return internal.NewPropFindResponse(fi.Path, propfind, props)
|
||||
}
|
||||
|
||||
func (b *backend) Proppatch(r *http.Request, update *internal.Propertyupdate) (*internal.Response, error) {
|
||||
func (b *backend) PropPatch(r *http.Request, update *internal.PropertyUpdate) (*internal.Response, error) {
|
||||
// TODO: return a failed Response instead
|
||||
return nil, internal.HTTPErrorf(http.StatusForbidden, "webdav: PROPPATCH is unsupported")
|
||||
}
|
||||
@ -285,11 +285,11 @@ func ServePrincipal(w http.ResponseWriter, r *http.Request, options *ServePrinci
|
||||
}
|
||||
|
||||
func servePrincipalPropfind(w http.ResponseWriter, r *http.Request, options *ServePrincipalOptions) error {
|
||||
var propfind internal.Propfind
|
||||
var propfind internal.PropFind
|
||||
if err := internal.DecodeXMLRequest(r, &propfind); err != nil {
|
||||
return err
|
||||
}
|
||||
props := map[xml.Name]internal.PropfindFunc{
|
||||
props := map[xml.Name]internal.PropFindFunc{
|
||||
internal.ResourceTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||
return internal.NewResourceType(principalName), nil
|
||||
},
|
||||
@ -307,11 +307,11 @@ func servePrincipalPropfind(w http.ResponseWriter, r *http.Request, options *Ser
|
||||
}
|
||||
}
|
||||
|
||||
resp, err := internal.NewPropfindResponse(r.URL.Path, &propfind, props)
|
||||
resp, err := internal.NewPropFindResponse(r.URL.Path, &propfind, props)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ms := internal.NewMultistatus(*resp)
|
||||
return internal.ServeMultistatus(w, ms)
|
||||
ms := internal.NewMultiStatus(*resp)
|
||||
return internal.ServeMultiStatus(w, ms)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user