caldav

package module
v3.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2017 License: MIT Imports: 4 Imported by: 0

README

go CalDAV

This is a Go lib that aims to implement the CalDAV specification (RFC4791). It allows the quick implementation of a CalDAV server in Go. Basically, it provides the request handlers that will handle the several CalDAV HTTP requests, fetch the appropriate resources, build and return the responses.

How to install
go get github.com/samedi/caldav-go
Dependencies

For dependency management, glide is used.

# install glide (once!)
curl https://glide.sh/get | sh

# install dependencies
glide install
How to use it

The easiest way to quickly implement a CalDAV server is by just using the lib's request handler. Example:

package mycaldav

import (
  "net/http"
  "github.com/samedi/caldav-go"
)

func runServer() {
  http.HandleFunc(PATH, caldav.RequestHandler)
  http.ListenAndServe(PORT, nil)
}

With that, all the HTTP requests (GET, PUT, REPORT, PROPFIND, etc) will be handled and responded by the caldav handler. In case of any HTTP methods not supported by the lib, a 501 Not Implemented response will be returned.

In case you want more flexibility to handle the requests, e.g., if you wanted to access the generated response before being sent back to the caller, you could do like:

package mycaldav

import (
  "net/http"
  "github.com/samedi/caldav-go"
)

func runServer() {
  http.HandleFunc(PATH, myHandler)
  http.ListenAndServe(PORT, nil)
}

func myHandler(writer http.ResponseWriter, request *http.Request) {
  response := caldav.HandleRequest(writer, request)
  // ... do something with the `response` ...
  // the response is written with the current `http.ResponseWriter` and ready to be sent back
  response.Write(writer)
}
Storage & Resources

The storage is where the caldav resources are stored. To interact with that, the caldav lib needs only a type that conforms with the data.Storage interface to operate on top of the storage. Basically, this interface defines all the CRUD functions to work on top of the resources. With that, resources can be stored anywhere: in the filesystem, in the cloud, database, etc. As long as the used storage implements all the required storage interface functions, the caldav lib will work fine.

For example, we could use the following dummy storage implementation:

type DummyStorage struct{
}

func (d *DummyStorage) GetResources(rpath string, withChildren bool) ([]Resource, error) {
  return []Resource{}, nil
}

func (d *DummyStorage) GetResourcesByFilters(rpath string, filters *ResourceFilter) ([]Resource, error) {
  return []Resource{}, nil
}

func (d *DummyStorage) GetResourcesByList(rpaths []string) ([]Resource, error) {
  return []Resource{}, nil
}

func (d *DummyStorage) GetResource(rpath string) (*Resource, bool, error) {
  return nil, false, nil
}

func (d *DummyStorage) GetShallowResource(rpath string) (*Resource, bool, error) {
  return nil, false, nil
}

func (d *DummyStorage) CreateResource(rpath, content string) (*Resource, error) {
  return nil, nil
}

func (d *DummyStorage) UpdateResource(rpath, content string) (*Resource, error) {
  return nil, nil
}

func (d *DummyStorage) DeleteResource(rpath string) error {
  return nil
}

Then we just need to tell the caldav lib to use our dummy storage:

dummyStg := new(DummyStorage)
caldav.SetupStorage(dummyStg)

All the CRUD operations on resources will then be forwarded to our dummy storage.

The default storage used (if none is explicitly set) is the data.FileStorage which deals with resources as files in the File System.

The resources can be of two types: collection and non-collection. A collection resource is basically a resource that has children resources, but does not have any data content. A non-collection resource is a resource that does not have children, but has data. In the case of a file storage, collections correspond to directories and non-collection to plain files. The data of a caldav resource is all the info that shows up in the calendar client, in the iCalendar format.

Features

Please check the CHANGELOG to see specific features that are currently implemented.

Contributing and testing

Everyone is welcome to contribute. Please raise an issue or pull request accordingly.

To run the tests:

./test.sh
License

MIT License.

Documentation

Index

Constants

View Source
const (
	VERSION = "3.0.0"
)

Variables

This section is empty.

Functions

func HandleRequest

func HandleRequest(request *http.Request) *handlers.Response

HandleRequest handles the given CALDAV request and returns the response. Useful when the caller wants to do something else with the response before writing it to the response stream.

func HandleRequestWithStorage

func HandleRequestWithStorage(request *http.Request, stg data.Storage) *handlers.Response

HandleRequestWithStorage handles the request the same way as `HandleRequest` does, but before, it sets the given storage that will be used throughout the request handling flow.

func RequestHandler

func RequestHandler(writer http.ResponseWriter, request *http.Request)

RequestHandler handles the given CALDAV request and writes the reponse righ away. This function is to be used by passing it directly as the handle func to the `http` lib. Example: http.HandleFunc("/", caldav.RequestHandler).

func SetupStorage

func SetupStorage(stg data.Storage)

func SetupUser

func SetupUser(username string)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL