mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
all: use variables for xml.Name values
This commit is contained in:
parent
557972089c
commit
34b2ebf940
@ -6,15 +6,11 @@ import (
|
|||||||
"github.com/emersion/go-vcard"
|
"github.com/emersion/go-vcard"
|
||||||
)
|
)
|
||||||
|
|
||||||
const namespace = "urn:ietf:params:xml:ns:carddav"
|
|
||||||
|
|
||||||
type AddressBook struct {
|
type AddressBook struct {
|
||||||
Href string
|
Href string
|
||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
var addressBookName = xml.Name{namespace, "addressbook"}
|
|
||||||
|
|
||||||
type AddressBookQuery struct {
|
type AddressBookQuery struct {
|
||||||
Props []string
|
Props []string
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,10 @@ import (
|
|||||||
"github.com/emersion/go-webdav/internal"
|
"github.com/emersion/go-webdav/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const namespace = "urn:ietf:params:xml:ns:carddav"
|
||||||
|
|
||||||
|
var addressBookName = xml.Name{namespace, "addressbook"}
|
||||||
|
|
||||||
type addressbookHomeSet struct {
|
type addressbookHomeSet struct {
|
||||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-home-set"`
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-home-set"`
|
||||||
Href string `xml:"href"`
|
Href string `xml:"href"`
|
||||||
|
@ -111,7 +111,7 @@ func (b *backend) Propfind(r *http.Request, propfind *internal.Propfind, depth i
|
|||||||
|
|
||||||
func (b *backend) propfindAddressBook(propfind *internal.Propfind) (*internal.Response, error) {
|
func (b *backend) propfindAddressBook(propfind *internal.Propfind) (*internal.Response, error) {
|
||||||
props := map[xml.Name]internal.PropfindFunc{
|
props := map[xml.Name]internal.PropfindFunc{
|
||||||
{"DAV:", "resourcetype"}: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.ResourceTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return internal.NewResourceType(internal.CollectionName, addressBookName), nil
|
return internal.NewResourceType(internal.CollectionName, addressBookName), nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -121,10 +121,7 @@ func (b *backend) propfindAddressBook(propfind *internal.Propfind) (*internal.Re
|
|||||||
|
|
||||||
func (b *backend) propfindAddressObject(propfind *internal.Propfind, ao *AddressObject) (*internal.Response, error) {
|
func (b *backend) propfindAddressObject(propfind *internal.Propfind, ao *AddressObject) (*internal.Response, error) {
|
||||||
props := map[xml.Name]internal.PropfindFunc{
|
props := map[xml.Name]internal.PropfindFunc{
|
||||||
{"DAV:", "resourcetype"}: func(*internal.RawXMLValue) (interface{}, error) {
|
internal.GetContentTypeName: func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return internal.NewResourceType(), nil
|
|
||||||
},
|
|
||||||
{"DAV:", "getcontenttype"}: func(*internal.RawXMLValue) (interface{}, error) {
|
|
||||||
return &internal.GetContentType{Type: vcard.MIMEType}, nil
|
return &internal.GetContentType{Type: vcard.MIMEType}, nil
|
||||||
},
|
},
|
||||||
// TODO getlastmodified, getetag
|
// TODO getlastmodified, getetag
|
||||||
|
@ -9,6 +9,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const Namespace = "DAV:"
|
||||||
|
|
||||||
type Status struct {
|
type Status struct {
|
||||||
Code int
|
Code int
|
||||||
Text string
|
Text string
|
||||||
@ -265,6 +267,14 @@ type GetLastModified struct {
|
|||||||
LastModified Time `xml:",chardata"`
|
LastModified Time `xml:",chardata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
ResourceTypeName = xml.Name{"DAV:", "resourcetype"}
|
||||||
|
GetContentLengthName = xml.Name{"DAV:", "getcontentlength"}
|
||||||
|
GetContentTypeName = xml.Name{"DAV:", "getcontenttype"}
|
||||||
|
GetLastModifiedName = xml.Name{"DAV:", "getlastmodified"}
|
||||||
|
GetETagName = xml.Name{"DAV:", "getetag"}
|
||||||
|
)
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc4918#section-14.5
|
// https://tools.ietf.org/html/rfc4918#section-14.5
|
||||||
type Error struct {
|
type Error struct {
|
||||||
XMLName xml.Name `xml:"DAV: error"`
|
XMLName xml.Name `xml:"DAV: error"`
|
||||||
|
@ -137,7 +137,7 @@ func (b *backend) propfind(propfind *internal.Propfind, name string, fi os.FileI
|
|||||||
func (b *backend) propfindFile(propfind *internal.Propfind, name string, fi os.FileInfo) (*internal.Response, error) {
|
func (b *backend) propfindFile(propfind *internal.Propfind, name string, fi os.FileInfo) (*internal.Response, error) {
|
||||||
props := make(map[xml.Name]internal.PropfindFunc)
|
props := make(map[xml.Name]internal.PropfindFunc)
|
||||||
|
|
||||||
props[xml.Name{"DAV:", "resourcetype"}] = func(*internal.RawXMLValue) (interface{}, error) {
|
props[internal.ResourceTypeName] = func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
var types []xml.Name
|
var types []xml.Name
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
types = append(types, internal.CollectionName)
|
types = append(types, internal.CollectionName)
|
||||||
@ -146,10 +146,10 @@ func (b *backend) propfindFile(propfind *internal.Propfind, name string, fi os.F
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !fi.IsDir() {
|
if !fi.IsDir() {
|
||||||
props[xml.Name{"DAV:", "getcontentlength"}] = func(*internal.RawXMLValue) (interface{}, error) {
|
props[internal.GetContentLengthName] = func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return &internal.GetContentLength{Length: fi.Size()}, nil
|
return &internal.GetContentLength{Length: fi.Size()}, nil
|
||||||
}
|
}
|
||||||
props[xml.Name{"DAV:", "getcontenttype"}] = func(*internal.RawXMLValue) (interface{}, error) {
|
props[internal.GetContentTypeName] = func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
t := mime.TypeByExtension(path.Ext(name))
|
t := mime.TypeByExtension(path.Ext(name))
|
||||||
if t == "" {
|
if t == "" {
|
||||||
// TODO: use http.DetectContentType
|
// TODO: use http.DetectContentType
|
||||||
@ -157,7 +157,7 @@ func (b *backend) propfindFile(propfind *internal.Propfind, name string, fi os.F
|
|||||||
}
|
}
|
||||||
return &internal.GetContentType{Type: t}, nil
|
return &internal.GetContentType{Type: t}, nil
|
||||||
}
|
}
|
||||||
props[xml.Name{"DAV:", "getlastmodified"}] = func(*internal.RawXMLValue) (interface{}, error) {
|
props[internal.GetLastModifiedName] = func(*internal.RawXMLValue) (interface{}, error) {
|
||||||
return &internal.GetLastModified{LastModified: internal.Time(fi.ModTime())}, nil
|
return &internal.GetLastModified{LastModified: internal.Time(fi.ModTime())}, nil
|
||||||
}
|
}
|
||||||
// TODO: getetag
|
// TODO: getetag
|
||||||
|
Loading…
Reference in New Issue
Block a user