webdav

package module
v0.0.0-...-c4abd28 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 13 Imported by: 0

README

go-webdav

Go Reference builds.sr.ht status

A Go library for WebDAV, CalDAV and CardDAV.

License

MIT

Documentation

Overview

Package webdav provides a client and server WebDAV filesystem implementation.

WebDAV is defined in RFC 4918.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPError

func NewHTTPError(statusCode int, cause error) error

NewHTTPError creates a new error that is associated with an HTTP status code and optionally an error that lead to it. Backends can use this functions to return errors that convey some semantics (e.g. 404 not found, 403 access denied, etc) while also providing an (optional) arbitrary error context (intended for humans).

func ServePrincipal

func ServePrincipal(w http.ResponseWriter, r *http.Request, options *ServePrincipalOptions)

ServePrincipal replies to requests for a principal URL.

Types

type BackendSuppliedHomeSet

type BackendSuppliedHomeSet interface {
	GetXMLName() xml.Name
}

BackendSuppliedHomeSet represents either a CalDAV calendar-home-set or a CardDAV addressbook-home-set. It should only be created via `caldav.NewCalendarHomeSet()` or `carddav.NewAddressbookHomeSet()`. Only to be used server-side, for listing a user's home sets as determined by the (external) backend.

type Capability

type Capability string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides access to a remote WebDAV filesystem.

func NewClient

func NewClient(c HTTPClient, endpoint string) (*Client, error)

func (*Client) CopyAll

func (c *Client) CopyAll(name, dest string, overwrite bool) error

func (*Client) Create

func (c *Client) Create(name string) (io.WriteCloser, error)

func (*Client) FindCurrentUserPrincipal

func (c *Client) FindCurrentUserPrincipal() (string, error)

func (*Client) Mkdir

func (c *Client) Mkdir(name string) error

func (*Client) MoveAll

func (c *Client) MoveAll(name, dest string, overwrite bool) error

func (*Client) Open

func (c *Client) Open(name string) (io.ReadCloser, error)

func (*Client) Readdir

func (c *Client) Readdir(name string, recursive bool) ([]FileInfo, error)

func (*Client) RemoveAll

func (c *Client) RemoveAll(name string) error

func (*Client) Stat

func (c *Client) Stat(name string) (*FileInfo, error)

type ConditionalMatch

type ConditionalMatch string

ConditionalMatch represents the value of a conditional header according to RFC 2068 section 14.25 and RFC 2068 section 14.26 The (optional) value can either be a wildcard or an ETag.

func (ConditionalMatch) ETag

func (val ConditionalMatch) ETag() (string, error)

func (ConditionalMatch) IsSet

func (val ConditionalMatch) IsSet() bool

func (ConditionalMatch) IsWildcard

func (val ConditionalMatch) IsWildcard() bool

type FileInfo

type FileInfo struct {
	Path     string
	Size     int64
	ModTime  time.Time
	IsDir    bool
	MIMEType string
	ETag     string
}

type FileSystem

type FileSystem interface {
	Open(name string) (io.ReadCloser, error)
	Stat(name string) (*FileInfo, error)
	Readdir(name string, recursive bool) ([]FileInfo, error)
	Create(name string) (io.WriteCloser, error)
	RemoveAll(name string) error
	Mkdir(name string) error
	Copy(name, dest string, recursive, overwrite bool) (created bool, err error)
	MoveAll(name, dest string, overwrite bool) (created bool, err error)
}

FileSystem is a WebDAV server backend.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient performs HTTP requests. It's implemented by *http.Client.

func HTTPClientWithBasicAuth

func HTTPClientWithBasicAuth(c HTTPClient, username, password string) HTTPClient

HTTPClientWithBasicAuth returns an HTTP client that adds basic authentication to all outgoing requests. If c is nil, http.DefaultClient is used.

type Handler

type Handler struct {
	FileSystem FileSystem
}

Handler handles WebDAV HTTP requests. It can be used to create a WebDAV server.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type LocalFileSystem

type LocalFileSystem string

func (LocalFileSystem) Copy

func (fs LocalFileSystem) Copy(src, dst string, recursive, overwrite bool) (created bool, err error)

func (LocalFileSystem) Create

func (fs LocalFileSystem) Create(name string) (io.WriteCloser, error)

func (LocalFileSystem) Mkdir

func (fs LocalFileSystem) Mkdir(name string) error

func (LocalFileSystem) MoveAll

func (fs LocalFileSystem) MoveAll(src, dst string, overwrite bool) (created bool, err error)

func (LocalFileSystem) Open

func (fs LocalFileSystem) Open(name string) (io.ReadCloser, error)

func (LocalFileSystem) Readdir

func (fs LocalFileSystem) Readdir(name string, recursive bool) ([]FileInfo, error)

func (LocalFileSystem) RemoveAll

func (fs LocalFileSystem) RemoveAll(name string) error

func (LocalFileSystem) Stat

func (fs LocalFileSystem) Stat(name string) (*FileInfo, error)

type ServePrincipalOptions

type ServePrincipalOptions struct {
	CurrentUserPrincipalPath string
	HomeSets                 []BackendSuppliedHomeSet
	Capabilities             []Capability
}

type UserPrincipalBackend

type UserPrincipalBackend interface {
	CurrentUserPrincipal(ctx context.Context) (string, error)
}

UserPrincipalBackend can determine the current user's principal URL for a given request context.

Directories

Path Synopsis
Package caldav provides a client and server CalDAV implementation.
Package caldav provides a client and server CalDAV implementation.
Package carddav provides a client and server CardDAV implementation.
Package carddav provides a client and server CardDAV implementation.
cmd
Package internal provides low-level helpers for WebDAV clients and servers.
Package internal provides low-level helpers for WebDAV clients and servers.

Jump to

Keyboard shortcuts

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