mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
caldav: add Client boilerplate
This commit is contained in:
parent
feea39c898
commit
6aea0eda2d
4
caldav/caldav.go
Normal file
4
caldav/caldav.go
Normal file
@ -0,0 +1,4 @@
|
||||
// Package caldav provides a client and server CalDAV implementation.
|
||||
//
|
||||
// CalDAV is defined in RFC 4791.
|
||||
package caldav
|
47
caldav/client.go
Normal file
47
caldav/client.go
Normal file
@ -0,0 +1,47 @@
|
||||
package caldav
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/emersion/go-webdav"
|
||||
"github.com/emersion/go-webdav/internal"
|
||||
)
|
||||
|
||||
// Client provides access to a remote CardDAV server.
|
||||
type Client struct {
|
||||
*webdav.Client
|
||||
|
||||
ic *internal.Client
|
||||
}
|
||||
|
||||
func NewClient(c *http.Client, endpoint string) (*Client, error) {
|
||||
wc, err := webdav.NewClient(c, endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ic, err := internal.NewClient(c, endpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Client{wc, ic}, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetBasicAuth(username, password string) {
|
||||
c.Client.SetBasicAuth(username, password)
|
||||
c.ic.SetBasicAuth(username, password)
|
||||
}
|
||||
|
||||
func (c *Client) FindCalendarHomeSet(principal string) (string, error) {
|
||||
propfind := internal.NewPropNamePropfind(calendarHomeSetName)
|
||||
resp, err := c.ic.PropfindFlat(principal, propfind)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var prop calendarHomeSet
|
||||
if err := resp.DecodeProp(&prop); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return prop.Href.Path, nil
|
||||
}
|
17
caldav/elements.go
Normal file
17
caldav/elements.go
Normal file
@ -0,0 +1,17 @@
|
||||
package caldav
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
|
||||
"github.com/emersion/go-webdav/internal"
|
||||
)
|
||||
|
||||
const namespace = "urn:ietf:params:xml:ns:caldav"
|
||||
|
||||
var calendarHomeSetName = xml.Name{namespace, "calendar-home-set"}
|
||||
|
||||
// https://tools.ietf.org/html/rfc4791#section-6.2.1
|
||||
type calendarHomeSet struct {
|
||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav calendar-home-set"`
|
||||
Href internal.Href `xml:"DAV: href"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user