From 8528c011639e038e2cd11b43d1d6d6f7e3dbbf4e Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Sun, 16 Oct 2022 01:02:00 +0200 Subject: [PATCH] updates API --- README.md | 85 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 31d9fe7..8b2443a 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,8 @@ included. ### Index * [func FixSlash(s string) string](#FixSlash) * [func FixSlashes(s string) string](#FixSlashes) +* [func IsErrCode(err error, code int) bool](#IsErrCode) +* [func IsErrNotFound(err error) bool](#IsErrNotFound) * [func Join(path0 string, path1 string) string](#Join) * [func PathEscape(path string) string](#PathEscape) * [func ReadConfig(uri, netrc string) (string, string)](#ReadConfig) @@ -175,8 +177,8 @@ included. * [func NewClient(uri, user, pw string) *Client](#NewClient) * [func (c *Client) Connect() error](#Client.Connect) * [func (c *Client) Copy(oldpath, newpath string, overwrite bool) error](#Client.Copy) - * [func (c *Client) Mkdir(path string, _ os.FileMode) error](#Client.Mkdir) - * [func (c *Client) MkdirAll(path string, _ os.FileMode) error](#Client.MkdirAll) + * [func (c *Client) Mkdir(path string, _ os.FileMode) (err error)](#Client.Mkdir) + * [func (c *Client) MkdirAll(path string, _ os.FileMode) (err error)](#Client.MkdirAll) * [func (c *Client) Read(path string) ([]byte, error)](#Client.Read) * [func (c *Client) ReadDir(path string) ([]os.FileInfo, error)](#Client.ReadDir) * [func (c *Client) ReadStream(path string) (io.ReadCloser, error)](#Client.ReadStream) @@ -189,8 +191,8 @@ included. * [func (c *Client) SetTimeout(timeout time.Duration)](#Client.SetTimeout) * [func (c *Client) SetTransport(transport http.RoundTripper)](#Client.SetTransport) * [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) + * [func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error)](#Client.Write) + * [func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err error)](#Client.WriteStream) * [type DigestAuth](#DigestAuth) * [func (d *DigestAuth) Authorize(req *http.Request, method string, path string)](#DigestAuth.Authorize) * [func (d *DigestAuth) Pass() string](#DigestAuth.Pass) @@ -212,32 +214,49 @@ included. * [func (n *NoAuth) Pass() string](#NoAuth.Pass) * [func (n *NoAuth) Type() string](#NoAuth.Type) * [func (n *NoAuth) User() string](#NoAuth.User) +* [type StatusError](#StatusError) + * [func (se StatusError) Error() string](#StatusError.Error) ##### Examples * [PathEscape](#example_PathEscape) ##### Package files -[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) [netrc.go](https://github.com/studio-b12/gowebdav/blob/master/netrc.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) [errors.go](https://github.com/studio-b12/gowebdav/blob/master/errors.go) [file.go](https://github.com/studio-b12/gowebdav/blob/master/file.go) [netrc.go](https://github.com/studio-b12/gowebdav/blob/master/netrc.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) +### func [FixSlash](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=354:384#L23) ``` go func FixSlash(s string) string ``` FixSlash appends a trailing / to our string -### func [FixSlashes](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=859:891#L53) +### func [FixSlashes](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=506:538#L31) ``` go func FixSlashes(s string) string ``` FixSlashes appends and prepends a / if they are missing -### func [Join](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=992:1036#L62) +### func [IsErrCode](https://github.com/studio-b12/gowebdav/blob/master/errors.go?s=355:395#L21) +``` go +func IsErrCode(err error, code int) bool +``` +IsErrCode returns true if the given error +is an os.PathError wrapping a StatusError +with the given status code. + +### func [IsErrNotFound](https://github.com/studio-b12/gowebdav/blob/master/errors.go?s=587:621#L31) +``` go +func IsErrNotFound(err error) bool +``` +IsErrNotFound is shorthand for IsErrCode +for status 404. + +### func [Join](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=639:683#L40) ``` go func Join(path0 string, path1 string) string ``` Join joins two paths -### func [PathEscape](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=506:541#L36) +### func [PathEscape](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=153:188#L14) ``` go func PathEscape(path string) string ``` @@ -250,7 +269,7 @@ func ReadConfig(uri, netrc string) (string, string) ReadConfig reads login and password configuration from ~/.netrc machine foo.com login username password 123456 -### func [String](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=1166:1197#L67) +### func [String](https://github.com/studio-b12/gowebdav/blob/master/utils.go?s=813:844#L45) ``` go func String(r io.Reader) string ``` @@ -272,6 +291,7 @@ Authenticator stub type BasicAuth struct { // contains filtered or unexported fields } + ``` BasicAuth structure holds our credentials @@ -304,6 +324,7 @@ User holds the BasicAuth username type Client struct { // contains filtered or unexported fields } + ``` Client defines our structure @@ -319,25 +340,25 @@ 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=6702:6770#L313) +#### func (\*Client) [Copy](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6818:6886#L323) ``` 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=5793:5849#L272) +#### func (\*Client) [Mkdir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5793:5855#L272) ``` go -func (c *Client) Mkdir(path string, _ os.FileMode) error +func (c *Client) Mkdir(path string, _ os.FileMode) (err error) ``` Mkdir makes a directory -#### func (\*Client) [MkdirAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6028:6087#L283) +#### func (\*Client) [MkdirAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6068:6133#L286) ``` go -func (c *Client) MkdirAll(path string, _ os.FileMode) error +func (c *Client) MkdirAll(path string, _ os.FileMode) (err error) ``` MkdirAll like mkdir -p, but for webdav -#### func (\*Client) [Read](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6876:6926#L318) +#### func (\*Client) [Read](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6992:7042#L328) ``` go func (c *Client) Read(path string) ([]byte, error) ``` @@ -349,13 +370,13 @@ 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=7237:7300#L336) +#### func (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7353:7416#L346) ``` go func (c *Client) ReadStream(path string) (io.ReadCloser, error) ``` ReadStream reads the stream for a given path -#### func (\*Client) [ReadStreamRange](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=8049:8139#L358) +#### func (\*Client) [ReadStreamRange](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=8165:8255#L368) ``` go func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error) ``` @@ -380,7 +401,7 @@ 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=6536:6606#L308) +#### func (\*Client) [Rename](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6652:6722#L318) ``` go func (c *Client) Rename(oldpath, newpath string, overwrite bool) error ``` @@ -416,15 +437,15 @@ 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=9051:9120#L388) +#### func (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=9260:9335#L402) ``` go -func (c *Client) Write(path string, data []byte, _ os.FileMode) error +func (c *Client) Write(path string, data []byte, _ os.FileMode) (err error) ``` Write writes data to a given path -#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=9476:9556#L411) +#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=9759:9845#L432) ``` go -func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error +func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) (err error) ``` WriteStream writes a stream @@ -433,6 +454,7 @@ WriteStream writes a stream type DigestAuth struct { // contains filtered or unexported fields } + ``` DigestAuth structure holds our credentials @@ -465,6 +487,7 @@ User holds the DigestAuth username type File struct { // contains filtered or unexported fields } + ``` File is our structure for a given file @@ -533,6 +556,7 @@ Sys ???? type NoAuth struct { // contains filtered or unexported fields } + ``` NoAuth structure holds our credentials @@ -560,5 +584,20 @@ func (n *NoAuth) User() string ``` User returns the current user +### type [StatusError](https://github.com/studio-b12/gowebdav/blob/master/errors.go?s=114:153#L10) +``` go +type StatusError struct { + Status int +} + +``` +StatusError implements error and wraps +an erroneous status code. + +#### func (StatusError) [Error](https://github.com/studio-b12/gowebdav/blob/master/errors.go?s=155:191#L14) +``` go +func (se StatusError) Error() string +``` + - - - Generated by [godoc2md](http://godoc.org/github.com/davecheney/godoc2md)