diff --git a/Makefile b/Makefile index ceaac02..c6a0062 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ ${BIN}: ${SRC} go build -o $@ ./cmd/gowebdav test: - go test -v ./... + go test -v --short ./... api: @sed '/^## API$$/,$$d' -i README.md @@ -22,7 +22,10 @@ api: check: gofmt -w -s $(SRC) + @echo gocyclo -over 15 . + @echo + golint ./... clean: @rm -f ${BIN} diff --git a/README.md b/README.md index 45c5c41..9911119 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,12 @@ # GoWebDAV [![Build Status](https://travis-ci.org/studio-b12/gowebdav.svg?branch=master)](https://travis-ci.org/studio-b12/gowebdav) +[![GoDoc](https://godoc.org/github.com/studio-b12/gowebdav?status.svg)](https://godoc.org/github.com/studio-b12/gowebdav) [![Go Report Card](https://goreportcard.com/badge/github.com/studio-b12/gowebdav)](https://goreportcard.com/report/github.com/studio-b12/gowebdav) -A WebDAV client and library for golang. +A golang WebDAV client library and command line tool. -## Install +## Install command line tool ```sh go get -u github.com/studio-b12/gowebdav/cmd/gowebdav @@ -24,8 +25,8 @@ Usage of gowebdav MKDIR MKDIRALL - GET - PUT + GET [] + PUT [] MV CP @@ -40,13 +41,37 @@ Usage of gowebdav User [ENV.USER] ``` -*Example* +*gowebdav wrapper script* + +Create a wrapper script for example `$EDITOR ./dav && chmod a+x ./dav` for your +server and use [pass](https://www.passwordstore.org/ "the standard unix password manager") +or similar tools to retrieve the password. ```sh -ROOT="https://webdav.server/" \ +#!/bin/sh + +ROOT="https://my.dav.server/" \ USER="foo" \ -PASSWORD="bar" \ -./gowebdav -X LS / +PASSWORD="$(pass dav/foo@my.dav.server)" \ +gowebdav $@ +``` + +*Examples* + +Using the `dav` wrapper: + +```sh +$ ./dav -X LS / + +$ echo hi dav! > hello && ./dav -X PUT /hello + +$ ./dav -X STAT /hello + +$ ./dav -X PUT /hello_dav hello + +$ ./dav -X GET /hello_dav + +$ ./dav -X GET /hello_dav hello.txt ``` ## LINKS @@ -65,7 +90,8 @@ PASSWORD="bar" \ * [Subdirectories](#pkg-subdirectories) ### Overview -Package gowebdav A golang WebDAV library +Package gowebdav is a WebDAV client library with a command line tool +included. ### Index * [func FixSlash(s string) string](#FixSlash) @@ -73,6 +99,12 @@ Package gowebdav A golang WebDAV library * [func Join(path0 string, path1 string) string](#Join) * [func PathEscape(path string) string](#PathEscape) * [func String(r io.Reader) string](#String) +* [type Authenticator](#Authenticator) +* [type BasicAuth](#BasicAuth) + * [func (b *BasicAuth) Authorize(c *Client, method string, path string)](#BasicAuth.Authorize) + * [func (b *BasicAuth) Pass() string](#BasicAuth.Pass) + * [func (b *BasicAuth) Type() string](#BasicAuth.Type) + * [func (b *BasicAuth) User() string](#BasicAuth.User) * [type Client](#Client) * [func NewClient(uri, user, pw string) *Client](#NewClient) * [func (c *Client) Connect() error](#Client.Connect) @@ -91,6 +123,11 @@ Package gowebdav A golang WebDAV library * [func (c *Client) Stat(path string) (os.FileInfo, error)](#Client.Stat) * [func (c *Client) Write(path string, data []byte, _ os.FileMode) error](#Client.Write) * [func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error](#Client.WriteStream) +* [type DigestAuth](#DigestAuth) + * [func (d *DigestAuth) Authorize(c *Client, method string, path string)](#DigestAuth.Authorize) + * [func (d *DigestAuth) Pass() string](#DigestAuth.Pass) + * [func (d *DigestAuth) Type() string](#DigestAuth.Type) + * [func (d *DigestAuth) User() string](#DigestAuth.User) * [type File](#File) * [func (f File) ContentType() string](#File.ContentType) * [func (f File) ETag() string](#File.ETag) @@ -101,12 +138,17 @@ Package gowebdav A golang WebDAV library * [func (f File) Size() int64](#File.Size) * [func (f File) String() string](#File.String) * [func (f File) Sys() interface{}](#File.Sys) +* [type NoAuth](#NoAuth) + * [func (n *NoAuth) Authorize(c *Client, method string, path string)](#NoAuth.Authorize) + * [func (n *NoAuth) Pass() string](#NoAuth.Pass) + * [func (n *NoAuth) Type() string](#NoAuth.Type) + * [func (n *NoAuth) User() string](#NoAuth.User) ##### Examples * [PathEscape](#example_PathEscape) ##### Package files -[client.go](https://github.com/studio-b12/gowebdav/blob/master/client.go) [file.go](https://github.com/studio-b12/gowebdav/blob/master/file.go) [requests.go](https://github.com/studio-b12/gowebdav/blob/master/requests.go) [utils.go](https://github.com/studio-b12/gowebdav/blob/master/utils.go) +[basicAuth.go](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go) [client.go](https://github.com/studio-b12/gowebdav/blob/master/client.go) [digestAuth.go](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go) [doc.go](https://github.com/studio-b12/gowebdav/blob/master/doc.go) [file.go](https://github.com/studio-b12/gowebdav/blob/master/file.go) [requests.go](https://github.com/studio-b12/gowebdav/blob/master/requests.go) [utils.go](https://github.com/studio-b12/gowebdav/blob/master/utils.go) ### func [FixSlash](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=707:737#L45) ``` go @@ -138,7 +180,50 @@ func String(r io.Reader) string ``` String pulls a string out of our io.Reader -### type [Client](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=220:301#L18) +### type [Authenticator](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=285:398#L24) +``` go +type Authenticator interface { + Type() string + User() string + Pass() string + Authorize(*Client, string, string) +} +``` +Authenticator stub + +### type [BasicAuth](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=94:145#L8) +``` go +type BasicAuth struct { + // contains filtered or unexported fields +} +``` +BasicAuth structure holds our credentials + +#### func (\*BasicAuth) [Authorize](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=461:529#L29) +``` go +func (b *BasicAuth) Authorize(c *Client, method string, path string) +``` +Authorize the current request + +#### func (\*BasicAuth) [Pass](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=376:409#L24) +``` go +func (b *BasicAuth) Pass() string +``` +Pass holds the BasicAuth password + +#### func (\*BasicAuth) [Type](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=189:222#L14) +``` go +func (b *BasicAuth) Type() string +``` +Type identifies the BasicAuthenticator + +#### func (\*BasicAuth) [User](https://github.com/studio-b12/gowebdav/blob/master/basicAuth.go?s=285:318#L19) +``` go +func (b *BasicAuth) User() string +``` +User holds the BasicAuth username + +### type [Client](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=157:261#L16) ``` go type Client struct { // contains filtered or unexported fields @@ -146,108 +231,140 @@ type Client struct { ``` Client defines our structure -#### func [NewClient](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=349:393#L25) +#### func [NewClient](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=902:946#L57) ``` go func NewClient(uri, user, pw string) *Client ``` NewClient creates a new instance of client -#### func (\*Client) [Connect](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1138:1170#L55) +#### func (\*Client) [Connect](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1516:1548#L77) ``` go func (c *Client) Connect() error ``` Connect connects to our dav server -#### func (\*Client) [Copy](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6060:6128#L281) +#### func (\*Client) [Copy](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6960:7028#L314) ``` go func (c *Client) Copy(oldpath, newpath string, overwrite bool) error ``` Copy copies a file from A to B -#### func (\*Client) [Mkdir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5151:5207#L240) +#### func (\*Client) [Mkdir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6051:6107#L273) ``` go func (c *Client) Mkdir(path string, _ os.FileMode) error ``` Mkdir makes a directory -#### func (\*Client) [MkdirAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5386:5445#L251) +#### func (\*Client) [MkdirAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6286:6345#L284) ``` go func (c *Client) MkdirAll(path string, _ os.FileMode) error ``` MkdirAll like mkdir -p, but for webdav -#### func (\*Client) [Read](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6234:6284#L286) +#### func (\*Client) [Read](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7134:7184#L319) ``` go func (c *Client) Read(path string) ([]byte, error) ``` Read reads the contents of a remote file -#### func (\*Client) [ReadDir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=2226:2286#L98) +#### func (\*Client) [ReadDir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=3126:3186#L131) ``` go func (c *Client) ReadDir(path string) ([]os.FileInfo, error) ``` ReadDir reads the contents of a remote directory -#### func (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6595:6658#L304) +#### func (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7495:7558#L337) ``` go func (c *Client) ReadStream(path string) (io.ReadCloser, error) ``` ReadStream reads the stream for a given path -#### func (\*Client) [Remove](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4657:4699#L217) +#### func (\*Client) [Remove](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5557:5599#L250) ``` go func (c *Client) Remove(path string) error ``` Remove removes a remote file -#### func (\*Client) [RemoveAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4765:4810#L222) +#### func (\*Client) [RemoveAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5665:5710#L255) ``` go func (c *Client) RemoveAll(path string) error ``` RemoveAll removes remote files -#### func (\*Client) [Rename](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5894:5964#L276) +#### func (\*Client) [Rename](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6794:6864#L309) ``` go func (c *Client) Rename(oldpath, newpath string, overwrite bool) error ``` Rename moves a file from A to B -#### func (\*Client) [SetHeader](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=721:766#L40) +#### func (\*Client) [SetHeader](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1099:1144#L62) ``` go func (c *Client) SetHeader(key, value string) ``` SetHeader lets us set arbitrary headers for a given client -#### func (\*Client) [SetTimeout](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=866:916#L45) +#### func (\*Client) [SetTimeout](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1244:1294#L67) ``` go func (c *Client) SetTimeout(timeout time.Duration) ``` SetTimeout exposes the ability to set a time limit for requests -#### func (\*Client) [SetTransport](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1009:1067#L50) +#### func (\*Client) [SetTransport](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=1387:1445#L72) ``` go func (c *Client) SetTransport(transport http.RoundTripper) ``` SetTransport exposes the ability to define custom transports -#### func (\*Client) [Stat](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=3613:3668#L165) +#### func (\*Client) [Stat](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4513:4568#L198) ``` go func (c *Client) Stat(path string) (os.FileInfo, error) ``` Stat returns the file stats for a specified path -#### func (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6949:7018#L319) +#### func (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7849:7918#L352) ``` go func (c *Client) Write(path string, data []byte, _ os.FileMode) error ``` Write writes data to a given path -#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7420:7500#L341) +#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=8320:8400#L374) ``` go func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error ``` WriteStream writes a stream +### type [DigestAuth](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=157:254#L14) +``` go +type DigestAuth struct { + // contains filtered or unexported fields +} +``` +DigestAuth structure holds our credentials + +#### func (\*DigestAuth) [Authorize](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=577:646#L36) +``` go +func (d *DigestAuth) Authorize(c *Client, method string, path string) +``` +Authorize the current request + +#### func (\*DigestAuth) [Pass](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=491:525#L31) +``` go +func (d *DigestAuth) Pass() string +``` +Pass holds the DigestAuth password + +#### func (\*DigestAuth) [Type](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=299:333#L21) +``` go +func (d *DigestAuth) Type() string +``` +Type identifies the DigestAuthenticator + +#### func (\*DigestAuth) [User](https://github.com/studio-b12/gowebdav/blob/master/digestAuth.go?s=398:432#L26) +``` go +func (d *DigestAuth) User() string +``` +User holds the DigestAuth username + ### type [File](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=93:253#L10) ``` go type File struct { @@ -310,5 +427,37 @@ func (f File) Sys() interface{} ``` Sys ???? +### type [NoAuth](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=442:490#L32) +``` go +type NoAuth struct { + // contains filtered or unexported fields +} +``` +NoAuth structure holds our credentials + +#### func (\*NoAuth) [Authorize](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=785:850#L53) +``` go +func (n *NoAuth) Authorize(c *Client, method string, path string) +``` +Authorize the current request + +#### func (\*NoAuth) [Pass](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=703:733#L48) +``` go +func (n *NoAuth) Pass() string +``` +Pass returns the current password + +#### func (\*NoAuth) [Type](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=529:559#L38) +``` go +func (n *NoAuth) Type() string +``` +Type identifies the authenticator + +#### func (\*NoAuth) [User](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=615:645#L43) +``` go +func (n *NoAuth) User() string +``` +User returns the current user + - - - Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md) diff --git a/client.go b/client.go index 65414ea..9bdbf21 100644 --- a/client.go +++ b/client.go @@ -1,4 +1,3 @@ -// Package gowebdav A golang WebDAV library package gowebdav import ( diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..e47d5ee --- /dev/null +++ b/doc.go @@ -0,0 +1,3 @@ +// Package gowebdav is a WebDAV client library with a command line tool +// included. +package gowebdav