Help us shape the future of Go! Take the 2026 Go Developer Survey

dav

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package dav is the explorer's WebDAV client: what browsing, downloading and uploading a share's files need of RFC 4918, and nothing else -- no locks, no properties beyond the four a listing shows.

It talks through any HTTP client (Doer): in a browser, the portal's (go-fileshare/portal/client), which adds the portal's header and keeps the token fresh; in a test, a plain one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(err error) bool

Exists says whether err is a MOVE or COPY refused because something is at the destination already (412 with Overwrite: F, RFC 4918 §10.6).

Types

type Client

type Client struct {

	// Piece is the size of one upload piece. Default 8 MiB: the portal
	// takes 16 MiB at most per PUT, and a smaller piece is a finer progress
	// bar and a smaller retry.
	Piece int64
	// contains filtered or unexported fields
}

Client is the WebDAV of one server, rooted at base -- the portal's /dav/<server>, or a server's own URL.

func New

func New(base string, do Doer) *Client

New is a client of the WebDAV at base.

func (*Client) Copy

func (c *Client) Copy(ctx context.Context, from, to string) error

Copy is Move's twin; see Move.

func (*Client) Delete

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

Delete removes p, a collection with everything in it.

func (*Client) DownloadURL

func (c *Client) DownloadURL(p string) string

DownloadURL is where a browser fetches p: a navigation, which the portal answers as an attachment.

func (*Client) Get added in v0.2.0

func (c *Client) Get(ctx context.Context, p string) (io.ReadCloser, error)

Get is the file p, to be read as it arrives and closed. A collection is not a file: p must not end in /.

func (*Client) List

func (c *Client) List(ctx context.Context, dir string) ([]Entry, error)

List is what the collection dir holds (PROPFIND, Depth 1), collections first, then by name; dir itself is not in it.

func (*Client) Mkdir

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

Mkdir makes the collection p.

func (*Client) Move

func (c *Client) Move(ctx context.Context, from, to string) error

Move renames from to to; Copy copies it there, on the server. Neither replaces what is there already: Overwrite is F (RFC 4918 §10.6 makes T the default, which would silently destroy a file a rename landed on), and an existing destination is an error Exists recognises. A 207 is a move or copy that failed in part, and is an error too.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, p string, src Source, overwrite bool, progress func(sent int64)) (err error)

Upload writes src at p, in pieces: an empty PUT of p.part, each piece appended where the last ended (go-filesystems/webdav v0.6.0), then a MOVE to p -- so nobody sees half a file under its name, and no request holds the whole file. progress, when not nil, is told the bytes sent so far. A failure leaves p as it was, and tries to remove the part file.

type Doer

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

Doer sends a request: *http.Client and the portal client's Doer are both.

type Entry

type Entry struct {
	Name     string
	Path     string // from the root of the server's WebDAV, with a leading /; a collection's ends in /
	Dir      bool
	Size     int64
	Modified time.Time
}

An Entry is one resource of a listing.

type Error

type Error struct {
	Op, Path string
	Status   int
	Message  string
}

Error is a status a request was refused with, and what the server said.

func (*Error) Error

func (e *Error) Error() string

type Source

type Source interface {
	Size() int64
	// ReadPiece reads the n bytes at off.
	ReadPiece(ctx context.Context, off, n int64) ([]byte, error)
}

A Source is a file to upload: the browser's File, a local file.

Jump to

Keyboard shortcuts

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