carddav: define XML names as globals

This commit is contained in:
Simon Ser 2020-01-18 12:43:47 +01:00
parent bf666bb2fb
commit 402593c5c6
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
3 changed files with 7 additions and 11 deletions

View File

@ -1,8 +1,6 @@
package carddav package carddav
import ( import (
"encoding/xml"
"github.com/emersion/go-vcard" "github.com/emersion/go-vcard"
) )

View File

@ -2,7 +2,6 @@ package carddav
import ( import (
"bytes" "bytes"
"encoding/xml"
"net/http" "net/http"
"github.com/emersion/go-vcard" "github.com/emersion/go-vcard"
@ -34,9 +33,7 @@ func (c *Client) SetBasicAuth(username, password string) {
} }
func (c *Client) FindAddressBookHomeSet(principal string) (string, error) { func (c *Client) FindAddressBookHomeSet(principal string) (string, error) {
name := xml.Name{namespace, "addressbook-home-set"} propfind := internal.NewPropNamePropfind(addressBookHomeSetName)
propfind := internal.NewPropNamePropfind(name)
resp, err := c.ic.PropfindFlat(principal, propfind) resp, err := c.ic.PropfindFlat(principal, propfind)
if err != nil { if err != nil {
return "", err return "", err
@ -51,10 +48,7 @@ func (c *Client) FindAddressBookHomeSet(principal string) (string, error) {
} }
func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, error) { func (c *Client) FindAddressBooks(addressBookHomeSet string) ([]AddressBook, error) {
resTypeName := xml.Name{"DAV:", "resourcetype"} propfind := internal.NewPropNamePropfind(internal.ResourceTypeName, addressBookDescriptionName)
descName := xml.Name{namespace, "addressbook-description"}
propfind := internal.NewPropNamePropfind(resTypeName, descName)
ms, err := c.ic.Propfind(addressBookHomeSet, internal.DepthOne, propfind) ms, err := c.ic.Propfind(addressBookHomeSet, internal.DepthOne, propfind)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -8,7 +8,11 @@ import (
const namespace = "urn:ietf:params:xml:ns:carddav" const namespace = "urn:ietf:params:xml:ns:carddav"
var addressBookName = xml.Name{namespace, "addressbook"} var (
addressBookName = xml.Name{namespace, "addressbook"}
addressBookHomeSetName = xml.Name{namespace, "addressbook-home-set"}
addressBookDescriptionName = xml.Name{namespace, "addressbook-description"}
)
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"`