Add CalDAV support, refactor

The filesystem storage backend now implements the required functions to
act as a basic CalDAV server. Some refactoring was done based on the
go-webdav development: introduce a UserPrincipalBackend, a new function
to serve the user principal URL, and more. See this PR for lots of
details: https://github.com/emersion/go-webdav/pull/62

Also adds a simple facility for debug output.
This commit is contained in:
Conrad Hoffmann 2022-03-23 10:38:14 +01:00
parent 5728f1ee27
commit 001917295d
7 changed files with 487 additions and 85 deletions

View file

@ -4,21 +4,23 @@ import (
"fmt"
"net/url"
"github.com/emersion/go-webdav"
"github.com/emersion/go-webdav/caldav"
"github.com/emersion/go-webdav/carddav"
)
func NewFromURL(storageURL string) (carddav.Backend, error) {
func NewFromURL(storageURL, caldavPrefix, carddavPrefix string, userPrincipalBackend webdav.UserPrincipalBackend) (caldav.Backend, carddav.Backend, error) {
u, err := url.Parse(storageURL)
if err != nil {
return nil, fmt.Errorf("error parsing storage URL: %s", err.Error())
return nil, nil, fmt.Errorf("error parsing storage URL: %s", err.Error())
}
switch u.Scheme {
case "file":
return NewFilesystem(u.Path)
return NewFilesystem(u.Path, caldavPrefix, carddavPrefix, userPrincipalBackend)
case "postgresql":
return NewPostgreSQL(), nil
return NewPostgreSQL()
default:
return nil, fmt.Errorf("no storage provider found for %s:// URL", u.Scheme)
return nil, nil, fmt.Errorf("no storage provider found for %s:// URL", u.Scheme)
}
}