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