carddav: go fmt

This commit is contained in:
emersion 2017-09-11 19:10:53 +02:00
parent 0581850864
commit fdd2e85cfe
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
4 changed files with 35 additions and 35 deletions

View File

@ -14,8 +14,8 @@ var (
) )
type AddressBookInfo struct { type AddressBookInfo struct {
Name string Name string
Description string Description string
MaxResourceSize int MaxResourceSize int
} }

View File

@ -28,7 +28,7 @@ func (w responseWriter) Write(b []byte) (int, error) {
} }
type Handler struct { type Handler struct {
ab AddressBook ab AddressBook
webdav *webdav.Handler webdav *webdav.Handler
} }
@ -154,7 +154,7 @@ func multiget(ctx context.Context, fs webdav.FileSystem, ls webdav.LockSystem, n
if !inserted { if !inserted {
pstats = append(pstats, webdav.Propstat{ pstats = append(pstats, webdav.Propstat{
Props: []webdav.Property{prop}, Props: []webdav.Property{prop},
Status: status, Status: status,
}) })
} }

View File

@ -18,30 +18,30 @@ import (
var ( var (
errNotYetImplemented = errors.New("not yet implemented") errNotYetImplemented = errors.New("not yet implemented")
errUnsupported = errors.New("unsupported") errUnsupported = errors.New("unsupported")
) )
const nsDAV = "DAV:" const nsDAV = "DAV:"
var ( var (
resourcetype = xml.Name{Space: nsDAV, Local: "resourcetype"} resourcetype = xml.Name{Space: nsDAV, Local: "resourcetype"}
displayname = xml.Name{Space: nsDAV, Local: "displayname"} displayname = xml.Name{Space: nsDAV, Local: "displayname"}
getcontenttype = xml.Name{Space: nsDAV, Local: "getcontenttype"} getcontenttype = xml.Name{Space: nsDAV, Local: "getcontenttype"}
) )
const nsCardDAV = "urn:ietf:params:xml:ns:carddav" const nsCardDAV = "urn:ietf:params:xml:ns:carddav"
var ( var (
addressBookDescription = xml.Name{Space: nsCardDAV, Local: "addressbook-description"} addressBookDescription = xml.Name{Space: nsCardDAV, Local: "addressbook-description"}
addressBookSupportedAddressData = xml.Name{Space: nsCardDAV, Local: "supported-address-data"} addressBookSupportedAddressData = xml.Name{Space: nsCardDAV, Local: "supported-address-data"}
addressBookMaxResourceSize = xml.Name{Space: nsCardDAV, Local: "max-resource-size"} addressBookMaxResourceSize = xml.Name{Space: nsCardDAV, Local: "max-resource-size"}
addressBookHomeSet = xml.Name{Space: nsCardDAV, Local: "addressbook-home-set"} addressBookHomeSet = xml.Name{Space: nsCardDAV, Local: "addressbook-home-set"}
) )
type fileInfo struct { type fileInfo struct {
name string name string
size int64 size int64
mode os.FileMode mode os.FileMode
modTime time.Time modTime time.Time
} }
@ -71,9 +71,9 @@ func (fi *fileInfo) Sys() interface{} {
type file struct { type file struct {
*bytes.Reader *bytes.Reader
fs *fileSystem fs *fileSystem
name string name string
ao AddressObject ao AddressObject
} }
func (f *file) Close() error { func (f *file) Close() error {
@ -131,8 +131,8 @@ func (f *file) Stat() (os.FileInfo, error) {
// TODO: getcontenttype for file // TODO: getcontenttype for file
type dir struct { type dir struct {
fs *fileSystem fs *fileSystem
name string name string
files []os.FileInfo files []os.FileInfo
n int n int
@ -164,9 +164,9 @@ func (d *dir) Readdir(count int) ([]os.FileInfo, error) {
d.files = make([]os.FileInfo, len(aos)) d.files = make([]os.FileInfo, len(aos))
for i, ao := range aos { for i, ao := range aos {
f := &file{ f := &file{
fs: d.fs, fs: d.fs,
name: ao.ID() + ".vcf", name: ao.ID() + ".vcf",
ao: ao, ao: ao,
} }
info, err := f.Stat() info, err := f.Stat()
@ -209,15 +209,15 @@ func (d *dir) DeadProps() (map[xml.Name]webdav.Property, error) {
return map[xml.Name]webdav.Property{ return map[xml.Name]webdav.Property{
resourcetype: webdav.Property{ resourcetype: webdav.Property{
XMLName: resourcetype, XMLName: resourcetype,
InnerXML: []byte(`<collection xmlns="DAV:"/><addressbook xmlns="urn:ietf:params:xml:ns:carddav"/>`), InnerXML: []byte(`<collection xmlns="DAV:"/><addressbook xmlns="urn:ietf:params:xml:ns:carddav"/>`),
}, },
displayname: webdav.Property{ displayname: webdav.Property{
XMLName: displayname, XMLName: displayname,
InnerXML: []byte(info.Name), InnerXML: []byte(info.Name),
}, },
addressBookDescription: webdav.Property{ addressBookDescription: webdav.Property{
XMLName: addressBookDescription, XMLName: addressBookDescription,
InnerXML: []byte(info.Description), InnerXML: []byte(info.Description),
}, },
addressBookSupportedAddressData: webdav.Property{ addressBookSupportedAddressData: webdav.Property{
@ -226,11 +226,11 @@ func (d *dir) DeadProps() (map[xml.Name]webdav.Property, error) {
`<address-data-type xmlns="urn:ietf:params:xml:ns:carddav" content-type="text/vcard" version="4.0"/>`), `<address-data-type xmlns="urn:ietf:params:xml:ns:carddav" content-type="text/vcard" version="4.0"/>`),
}, },
addressBookMaxResourceSize: webdav.Property{ addressBookMaxResourceSize: webdav.Property{
XMLName: addressBookMaxResourceSize, XMLName: addressBookMaxResourceSize,
InnerXML: []byte(strconv.Itoa(info.MaxResourceSize)), InnerXML: []byte(strconv.Itoa(info.MaxResourceSize)),
}, },
addressBookHomeSet: webdav.Property{ addressBookHomeSet: webdav.Property{
XMLName: addressBookHomeSet, XMLName: addressBookHomeSet,
InnerXML: []byte(`<href xmlns="DAV:">/</href>`), InnerXML: []byte(`<href xmlns="DAV:">/</href>`),
}, },
}, nil }, nil
@ -255,7 +255,7 @@ func (fs *fileSystem) addressObjectID(name string) string {
func (fs *fileSystem) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) { func (fs *fileSystem) OpenFile(ctx context.Context, name string, flag int, perm os.FileMode) (webdav.File, error) {
if name == "/" { if name == "/" {
return &dir{ return &dir{
fs: fs, fs: fs,
name: name, name: name,
}, nil }, nil
} }
@ -267,9 +267,9 @@ func (fs *fileSystem) OpenFile(ctx context.Context, name string, flag int, perm
} }
return &file{ return &file{
fs: fs, fs: fs,
name: name, name: name,
ao: ao, ao: ao,
}, nil }, nil
} }

View File

@ -8,17 +8,17 @@ import (
// https://tools.ietf.org/html/rfc6352#section-10.7 // https://tools.ietf.org/html/rfc6352#section-10.7
type addressbookMultiget struct { type addressbookMultiget struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-multiget"` XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-multiget"`
Allprop *struct{} `xml:"DAV: allprop"` Allprop *struct{} `xml:"DAV: allprop"`
Propname *struct{} `xml:"DAV: propname"` Propname *struct{} `xml:"DAV: propname"`
Prop webdav.PropfindProps `xml:"DAV: prop"` Prop webdav.PropfindProps `xml:"DAV: prop"`
Href []string `xml:"DAV: href"` Href []string `xml:"DAV: href"`
} }
// TODO // TODO
type addressData struct { type addressData struct {
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav address-data"` XMLName xml.Name `xml:"urn:ietf:params:xml:ns:carddav address-data"`
ContentType string `xml:"content-type,attr"` ContentType string `xml:"content-type,attr"`
Version string `xml:"version,attr"` Version string `xml:"version,attr"`
Prop []string `xml:"prop>name,attr"` Prop []string `xml:"prop>name,attr"`
} }