webdav

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 13 Imported by: 15

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 added in v0.4.0

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 added in v0.4.0

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

ServePrincipal replies to requests for a principal URL.

Types

type BackendSuppliedHomeSet added in v0.4.0

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 added in v0.4.0

type Capability string

Capability indicates the features that a server supports.

type Client added in v0.2.0

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

Client provides access to a remote WebDAV filesystem.

func NewClient added in v0.2.0

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

NewClient creates a new WebDAV client.

If the HTTPClient is nil, http.DefaultClient is used.

To use HTTP basic authentication, HTTPClientWithBasicAuth can be used.

func (*Client) Copy added in v0.5.0

func (c *Client) Copy(ctx context.Context, name, dest string, options *CopyOptions) error

Copy copies a file.

By default, if the file is a directory, all descendants are recursively copied as well.

func (*Client) Create added in v0.2.0

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

Create writes a file's contents.

func (*Client) FindCurrentUserPrincipal added in v0.2.0

func (c *Client) FindCurrentUserPrincipal(ctx context.Context) (string, error)

FindCurrentUserPrincipal finds the current user's principal path.

func (*Client) Mkdir added in v0.2.0

func (c *Client) Mkdir(ctx context.Context, name string) error

Mkdir creates a new directory.

func (*Client) Move added in v0.5.0

func (c *Client) Move(ctx context.Context, name, dest string, options *MoveOptions) error

Move moves a file.

func (*Client) Open added in v0.2.0

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

Open fetches a file's contents.

func (*Client) ReadDir added in v0.5.0

func (c *Client) ReadDir(ctx context.Context, name string, recursive bool) ([]FileInfo, error)

ReadDir lists files in a directory.

func (*Client) RemoveAll added in v0.2.0

func (c *Client) RemoveAll(ctx context.Context, name string) error

RemoveAll deletes a file. If the file is a directory, all of its descendants are recursively deleted as well.

func (*Client) Stat added in v0.2.0

func (c *Client) Stat(ctx context.Context, name string) (*FileInfo, error)

Stat fetches a FileInfo for a single file.

type ConditionalMatch added in v0.4.0

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 added in v0.4.0

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

func (ConditionalMatch) IsSet added in v0.4.0

func (val ConditionalMatch) IsSet() bool

func (ConditionalMatch) IsWildcard added in v0.4.0

func (val ConditionalMatch) IsWildcard() bool

type CopyOptions added in v0.5.0

type CopyOptions struct {
	NoRecursive bool
	NoOverwrite bool
}

type FileInfo added in v0.2.0

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

FileInfo holds information about a WebDAV file.

type FileSystem

type FileSystem interface {
	Open(ctx context.Context, name string) (io.ReadCloser, error)
	Stat(ctx context.Context, name string) (*FileInfo, error)
	ReadDir(ctx context.Context, name string, recursive bool) ([]FileInfo, error)
	Create(ctx context.Context, name string) (io.WriteCloser, error)
	RemoveAll(ctx context.Context, name string) error
	Mkdir(ctx context.Context, name string) error
	Copy(ctx context.Context, name, dest string, options *CopyOptions) (created bool, err error)
	Move(ctx context.Context, name, dest string, options *MoveOptions) (created bool, err error)
}

FileSystem is a WebDAV server backend.

type HTTPClient added in v0.3.0

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

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

func HTTPClientWithBasicAuth added in v0.3.0

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 added in v0.2.0

type LocalFileSystem string

LocalFileSystem implements FileSystem for a local directory.

func (LocalFileSystem) Copy added in v0.2.0

func (fs LocalFileSystem) Copy(ctx context.Context, src, dst string, options *CopyOptions) (created bool, err error)

func (LocalFileSystem) Create added in v0.2.0

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

func (LocalFileSystem) Mkdir added in v0.2.0

func (fs LocalFileSystem) Mkdir(ctx context.Context, name string) error

func (LocalFileSystem) Move added in v0.5.0

func (fs LocalFileSystem) Move(ctx context.Context, src, dst string, options *MoveOptions) (created bool, err error)

func (LocalFileSystem) Open added in v0.2.0

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

func (LocalFileSystem) ReadDir added in v0.5.0

func (fs LocalFileSystem) ReadDir(ctx context.Context, name string, recursive bool) ([]FileInfo, error)

func (LocalFileSystem) RemoveAll added in v0.2.0

func (fs LocalFileSystem) RemoveAll(ctx context.Context, name string) error

func (LocalFileSystem) Stat added in v0.2.0

func (fs LocalFileSystem) Stat(ctx context.Context, name string) (*FileInfo, error)

type MoveOptions added in v0.5.0

type MoveOptions struct {
	NoOverwrite bool
}

type ServePrincipalOptions added in v0.4.0

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

ServePrincipalOptions holds options for ServePrincipal.

type UserPrincipalBackend added in v0.4.0

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