feat: implement caldav search
This commit is contained in:
53
vendor/github.com/dolanor/caldav-go/http/client.go
generated
vendored
Normal file
53
vendor/github.com/dolanor/caldav-go/http/client.go
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/dolanor/caldav-go/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// a client for making HTTP requests
|
||||
type Client struct {
|
||||
native *http.Client
|
||||
server *Server
|
||||
requestHeaders map[string]string
|
||||
}
|
||||
|
||||
func (c *Client) SetHeader(key string, value string) {
|
||||
if c.requestHeaders == nil {
|
||||
c.requestHeaders = map[string]string{}
|
||||
}
|
||||
c.requestHeaders[key] = value
|
||||
}
|
||||
|
||||
// downcasts to the native HTTP interface
|
||||
func (c *Client) Native() *http.Client {
|
||||
return c.native
|
||||
}
|
||||
|
||||
// returns the embedded HTTP server reference
|
||||
func (c *Client) Server() *Server {
|
||||
return c.server
|
||||
}
|
||||
|
||||
// executes an HTTP request
|
||||
func (c *Client) Do(req *Request) (*Response, error) {
|
||||
for key, value := range c.requestHeaders {
|
||||
req.Header.Add(key, value)
|
||||
}
|
||||
if resp, err := c.Native().Do((*http.Request)(req)); err != nil {
|
||||
return nil, utils.NewError(c.Do, "unable to execute HTTP request", c, err)
|
||||
} else {
|
||||
return NewResponse(resp), nil
|
||||
}
|
||||
}
|
||||
|
||||
// creates a new client for communicating with an HTTP server
|
||||
func NewClient(server *Server, native *http.Client) *Client {
|
||||
return &Client{server: server, native: native}
|
||||
}
|
||||
|
||||
// creates a new client for communicating with a server
|
||||
// uses the default HTTP client from net/http
|
||||
func NewDefaultClient(server *Server) *Client {
|
||||
return NewClient(server, http.DefaultClient)
|
||||
}
|
39
vendor/github.com/dolanor/caldav-go/http/request.go
generated
vendored
Normal file
39
vendor/github.com/dolanor/caldav-go/http/request.go
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/dolanor/caldav-go/utils"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// an HTTP request object
|
||||
type Request http.Request
|
||||
|
||||
// downcasts the request to the native HTTP interface
|
||||
func (r *Request) Native() *http.Request {
|
||||
return (*http.Request)(r)
|
||||
}
|
||||
|
||||
// creates a new HTTP request object
|
||||
func NewRequest(method string, urlstr string, body ...io.ReadCloser) (*Request, error) {
|
||||
|
||||
var err error
|
||||
var r = new(http.Request)
|
||||
|
||||
if len(body) > 0 && body[0] != nil {
|
||||
r, err = http.NewRequest(method, urlstr, body[0])
|
||||
} else {
|
||||
r, err = http.NewRequest(method, urlstr, nil)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, utils.NewError(NewRequest, "unable to create request", urlstr, err)
|
||||
} else if auth := r.URL.User; auth != nil {
|
||||
pass, _ := auth.Password()
|
||||
r.SetBasicAuth(auth.Username(), pass)
|
||||
r.URL.User = nil
|
||||
}
|
||||
|
||||
return (*Request)(r), nil
|
||||
|
||||
}
|
18
vendor/github.com/dolanor/caldav-go/http/response.go
generated
vendored
Normal file
18
vendor/github.com/dolanor/caldav-go/http/response.go
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// an HTTP response object
|
||||
type Response http.Response
|
||||
|
||||
// downcasts the response to the native HTTP interface
|
||||
func (r *Response) Native() *http.Response {
|
||||
return (*http.Response)(r)
|
||||
}
|
||||
|
||||
// creates a new HTTP response object
|
||||
func NewResponse(response *http.Response) *Response {
|
||||
return (*Response)(response)
|
||||
}
|
48
vendor/github.com/dolanor/caldav-go/http/server.go
generated
vendored
Normal file
48
vendor/github.com/dolanor/caldav-go/http/server.go
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/dolanor/caldav-go/utils"
|
||||
"io"
|
||||
"log"
|
||||
"net/url"
|
||||
spath "path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ = log.Print
|
||||
|
||||
// a server that accepts HTTP requests
|
||||
type Server struct {
|
||||
baseUrl *url.URL
|
||||
}
|
||||
|
||||
// creates a reference to an http server
|
||||
func NewServer(baseUrlStr string) (*Server, error) {
|
||||
var err error
|
||||
var s = new(Server)
|
||||
if s.baseUrl, err = url.Parse(baseUrlStr); err != nil {
|
||||
return nil, utils.NewError(NewServer, "unable to parse server base url", baseUrlStr, err)
|
||||
} else {
|
||||
return s, nil
|
||||
}
|
||||
}
|
||||
|
||||
// converts a path name to an absolute URL
|
||||
func (s *Server) UserInfo() *url.Userinfo {
|
||||
return s.baseUrl.User
|
||||
}
|
||||
|
||||
// converts a path name to an absolute URL
|
||||
func (s *Server) AbsUrlStr(path string) string {
|
||||
uri := *s.baseUrl
|
||||
uri.Path = spath.Join(uri.Path, path)
|
||||
if strings.HasSuffix(path, "/") {
|
||||
uri.Path = uri.Path + "/"
|
||||
}
|
||||
return uri.String()
|
||||
}
|
||||
|
||||
// creates a new HTTP request object
|
||||
func (s *Server) NewRequest(method string, path string, body ...io.ReadCloser) (*Request, error) {
|
||||
return NewRequest(method, s.AbsUrlStr(path), body...)
|
||||
}
|
Reference in New Issue
Block a user