From 34368960d0c72b96ae948902604b3ddc52ce866f Mon Sep 17 00:00:00 2001 From: Christoph Polcin Date: Wed, 23 May 2018 14:15:46 +0200 Subject: [PATCH] refactor --- README.md | 30 +++++++++++++++--------------- client.go | 16 ++++------------ 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index ccf2ce5..6aa83f1 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Package gowebdav A golang WebDAV library * [type Client](#Client) * [func NewClient(uri string, user string, pw string) *Client](#NewClient) * [func (c *Client) Connect() error](#Client.Connect) - * [func (c *Client) Copy(oldpath string, newpath string, overwrite bool) error](#Client.Copy) + * [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) Read(path string) ([]byte, error)](#Client.Read) @@ -72,7 +72,7 @@ Package gowebdav A golang WebDAV library * [func (c *Client) ReadStream(path string) (io.ReadCloser, error)](#Client.ReadStream) * [func (c *Client) Remove(path string) error](#Client.Remove) * [func (c *Client) RemoveAll(path string) error](#Client.RemoveAll) - * [func (c *Client) Rename(oldpath string, newpath string, overwrite bool) error](#Client.Rename) + * [func (c *Client) Rename(oldpath, newpath string, overwrite bool) error](#Client.Rename) * [func (c *Client) SetHeader(key, value string)](#Client.SetHeader) * [func (c *Client) SetTimeout(timeout time.Duration)](#Client.SetTimeout) * [func (c *Client) SetTransport(transport http.RoundTripper)](#Client.SetTransport) @@ -146,25 +146,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=6149:6224#L289) +#### func (\*Client) [Copy](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6074:6142#L281) ``` go -func (c *Client) Copy(oldpath string, newpath string, overwrite bool) error +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=5233:5289#L248) +#### func (\*Client) [Mkdir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5165:5221#L240) ``` 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=5468:5527#L259) +#### func (\*Client) [MkdirAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5400:5459#L251) ``` 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=6330:6380#L294) +#### func (\*Client) [Read](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6248:6298#L286) ``` go func (c *Client) Read(path string) ([]byte, error) ``` @@ -176,27 +176,27 @@ 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=6691:6754#L312) +#### func (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6609:6672#L304) ``` 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=4739:4781#L225) +#### func (\*Client) [Remove](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4671:4713#L217) ``` 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=4847:4892#L230) +#### func (\*Client) [RemoveAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4779:4824#L222) ``` 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=5976:6053#L284) +#### func (\*Client) [Rename](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5908:5978#L276) ``` go -func (c *Client) Rename(oldpath string, newpath string, overwrite bool) error +func (c *Client) Rename(oldpath, newpath string, overwrite bool) error ``` Rename moves a file from A to B @@ -218,19 +218,19 @@ 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=3661:3716#L169) +#### func (\*Client) [Stat](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=3627:3682#L165) ``` 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=7045:7114#L327) +#### func (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6963:7032#L319) ``` 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=7516:7596#L349) +#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7434:7514#L341) ``` go func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error ``` diff --git a/client.go b/client.go index dd9cbd7..532a894 100644 --- a/client.go +++ b/client.go @@ -155,11 +155,7 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) { if err != nil { if _, ok := err.(*os.PathError); !ok { - err = &os.PathError{ - Op: "ReadDir", - Path: path, - Err: err, - } + err = newPathErrorErr("ReadDir", path, err) } } return files, err @@ -211,11 +207,7 @@ func (c *Client) Stat(path string) (os.FileInfo, error) { if err != nil { if _, ok := err.(*os.PathError); !ok { - err = &os.PathError{ - Op: "ReadDir", - Path: path, - Err: err, - } + err = newPathErrorErr("ReadDir", path, err) } } return f, err @@ -281,12 +273,12 @@ func (c *Client) MkdirAll(path string, _ os.FileMode) error { } // Rename moves a file from A to B -func (c *Client) Rename(oldpath string, newpath string, overwrite bool) error { +func (c *Client) Rename(oldpath, newpath string, overwrite bool) error { return c.copymove("MOVE", oldpath, newpath, overwrite) } // Copy copies a file from A to B -func (c *Client) Copy(oldpath string, newpath string, overwrite bool) error { +func (c *Client) Copy(oldpath, newpath string, overwrite bool) error { return c.copymove("COPY", oldpath, newpath, overwrite) }