Rig up CardDAV backend to HTTP server

References: https://todo.sr.ht/~sircmpwn/tokidoki/3
This commit is contained in:
Simon Ser 2022-02-21 11:39:57 +01:00
parent 13008e0d96
commit 97f86226d6
4 changed files with 50 additions and 3 deletions

View File

@ -6,10 +6,12 @@ import (
"net/http" "net/http"
"os" "os"
"github.com/emersion/go-webdav/carddav"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware" "github.com/go-chi/chi/v5/middleware"
"git.sr.ht/~sircmpwn/tokidoki/auth" "git.sr.ht/~sircmpwn/tokidoki/auth"
"git.sr.ht/~sircmpwn/tokidoki/storage"
) )
func main() { func main() {
@ -31,9 +33,8 @@ func main() {
authProvider := auth.NewIMAP("imap.migadu.com:993", true) authProvider := auth.NewIMAP("imap.migadu.com:993", true)
mux.Use(authProvider.Middleware()) mux.Use(authProvider.Middleware())
mux.Get("/", func(w http.ResponseWriter, r *http.Request) { backend := storage.NewPostgreSQL()
w.Write([]byte("Hello world!\n")) mux.Handle("/", &carddav.Handler{Backend: backend})
})
server := http.Server{ server := http.Server{
Addr: addr, Addr: addr,

2
go.mod
View File

@ -5,6 +5,8 @@ go 1.17
require ( require (
github.com/emersion/go-imap v1.2.0 // indirect github.com/emersion/go-imap v1.2.0 // indirect
github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac // indirect github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac // indirect
github.com/emersion/go-vcard v0.0.0-20210521075357-3445b9171995 // indirect
github.com/emersion/go-webdav v0.3.1 // indirect
github.com/go-chi/chi/v5 v5.0.7 // indirect github.com/go-chi/chi/v5 v5.0.7 // indirect
golang.org/x/text v0.3.7 // indirect golang.org/x/text v0.3.7 // indirect
) )

6
go.sum
View File

@ -1,3 +1,4 @@
github.com/emersion/go-ical v0.0.0-20200224201310-cd514449c39e/go.mod h1:4xVTBPcT43a1pp3vdaa+FuRdX5XhKCZPpWv7m0z9ByM=
github.com/emersion/go-imap v1.2.0 h1:lyUQ3+EVM21/qbWE/4Ya5UG9r5+usDxlg4yfp3TgHFA= github.com/emersion/go-imap v1.2.0 h1:lyUQ3+EVM21/qbWE/4Ya5UG9r5+usDxlg4yfp3TgHFA=
github.com/emersion/go-imap v1.2.0/go.mod h1:Qlx1FSx2FTxjnjWpIlVNEuX+ylerZQNFE5NsmKFSejY= github.com/emersion/go-imap v1.2.0/go.mod h1:Qlx1FSx2FTxjnjWpIlVNEuX+ylerZQNFE5NsmKFSejY=
github.com/emersion/go-message v0.15.0/go.mod h1:wQUEfE+38+7EW8p8aZ96ptg6bAb1iwdgej19uXASlE4= github.com/emersion/go-message v0.15.0/go.mod h1:wQUEfE+38+7EW8p8aZ96ptg6bAb1iwdgej19uXASlE4=
@ -5,6 +6,11 @@ github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTe
github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac h1:tn/OQ2PmwQ0XFVgAHfjlLyqMewry25Rz7jWnVoh4Ggs= github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac h1:tn/OQ2PmwQ0XFVgAHfjlLyqMewry25Rz7jWnVoh4Ggs=
github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= github.com/emersion/go-sasl v0.0.0-20211008083017-0b9dcfb154ac/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U= github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U=
github.com/emersion/go-vcard v0.0.0-20191221110513-5f81fa0d3cc7/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM=
github.com/emersion/go-vcard v0.0.0-20210521075357-3445b9171995 h1:DpVfmcoBs6o9VYcccNWbuKFQxuHCgt25/y4q9H8AUvc=
github.com/emersion/go-vcard v0.0.0-20210521075357-3445b9171995/go.mod h1:HMJKR5wlh/ziNp+sHEDV2ltblO4JD2+IdDOWtGcQBTM=
github.com/emersion/go-webdav v0.3.1 h1:8ISu6AlBwu7DKg9RQE3iRpE3CPM8Bfpfz7L3bi/xlGI=
github.com/emersion/go-webdav v0.3.1/go.mod h1:uSM1VveeKtogBVWaYccTksToczooJ0rrVGNsgnDsr4Q=
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

View File

@ -0,0 +1,38 @@
package storage
import (
"github.com/emersion/go-vcard"
"github.com/emersion/go-webdav/carddav"
)
type psqlBackend struct{}
var _ carddav.Backend = (*psqlBackend)(nil)
func NewPostgreSQL() carddav.Backend {
return &psqlBackend{}
}
func (*psqlBackend) AddressBook() (*carddav.AddressBook, error) {
panic("TODO")
}
func (*psqlBackend) GetAddressObject(path string, req *carddav.AddressDataRequest) (*carddav.AddressObject, error) {
panic("TODO")
}
func (*psqlBackend) ListAddressObjects(req *carddav.AddressDataRequest) ([]carddav.AddressObject, error) {
panic("TODO")
}
func (*psqlBackend) QueryAddressObjects(query *carddav.AddressBookQuery) ([]carddav.AddressObject, error) {
panic("TODO")
}
func (*psqlBackend) PutAddressObject(path string, card vcard.Card) (loc string, err error) {
panic("TODO")
}
func (*psqlBackend) DeleteAddressObject(path string) error {
panic("TODO")
}