commit 4fc0a77565702f9bf498485d42336502f2ee9776 Author: Andy Hsu <i@nn.ci> Date: Fri Oct 20 21:06:25 2023 +0800 fix(baidu_netdisk): upload file > 4GB (close #5392) commit aaffaee2b54fc067d240ea0c20ea3c2f39615d6e Author: gmugu <94156510@qq.com> Date: Thu Oct 19 19:17:53 2023 +0800 perf(webdav): support request with cookies (#5391) commit 8ef8023c20bfeee97ec82155b52eae0d80b1410e Author: NewbieOrange <NewbieOrange@users.noreply.github.com> Date: Thu Oct 19 19:17:09 2023 +0800 fix(aliyundrive_open): upload progress for normal upload (#5398) commit cdfbe6dcf2b361e4c93c2703c2f8c9bddeac0ee6 Author: foxxorcat <95907542+foxxorcat@users.noreply.github.com> Date: Wed Oct 18 16:27:07 2023 +0800 fix: hash gcid empty file (#5394) commit 94d028743abf8e0d736f80c0ec4fb294a1cc064c Author: Andy Hsu <i@nn.ci> Date: Sat Oct 14 13:17:51 2023 +0800 ci: remove `pr-welcome` label when close issue [skip ci] commit 7f7335435c2f32a3eef76fac4c4f783d9d8624fd Author: itsHenry <2671230065@qq.com> Date: Sat Oct 14 13:12:46 2023 +0800 feat(cloudreve): support thumbnail (#5373 close #5348) * feat(cloudreve): support thumbnail * chore: remove unnecessary code commit b9e192b29cffddf14a0dfb2d3885def57a56ce16 Author: foxxorcat <95907542+foxxorcat@users.noreply.github.com> Date: Thu Oct 12 20:57:12 2023 +0800 fix(115): limit request rate (#5367 close #5275) * fix(115):limit request rate * chore(115): fix unit of `limit_rate` --------- Co-authored-by: Andy Hsu <i@nn.ci> commit 69a98eaef612b58596e5c26c341b6d7cedecdf19 Author: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Date: Wed Oct 11 22:01:55 2023 +0800 fix(deps): update module github.com/aliyun/aliyun-oss-go-sdk to v2.2.9+incompatible (#5141) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> commit 1ebc96a4e5220c979fd581bb3b5640e9436f6665 Author: Andy Hsu <i@nn.ci> Date: Tue Oct 10 18:32:00 2023 +0800 fix(wopan): fatal error concurrent map writes (close #5352) commit 66e2324cac75cb3ef05af45dbdd10b124d534aff Author: Andy Hsu <i@nn.ci> Date: Tue Oct 10 18:23:11 2023 +0800 chore(deps): upgrade dependencies commit 7600dc28df137c439e538b4257731c33a63db9b5 Author: Andy Hsu <i@nn.ci> Date: Tue Oct 10 18:13:58 2023 +0800 fix(aliyundrive_open): change default api to raw server (close #5358) commit 8ef89ad0a496d5acc398794c0afa4f77c67ad371 Author: foxxorcat <95907542+foxxorcat@users.noreply.github.com> Date: Tue Oct 10 18:08:27 2023 +0800 fix(baidu_netdisk): hash and `error 2` (#5356) * fix(baidu):hash and error:2 * fix:invalid memory address commit 35d672217dde69e65b41b1fcd9786c1cfebcdc45 Author: jeffmingup <1960588251@qq.com> Date: Sun Oct 8 19:29:45 2023 +0800 fix(onedrive_app): incorrect api on `_accessToken` (#5346) commit 1a283bb2720eff6d1b0c1dd6f1667a6449905a9b Author: foxxorcat <95907542+foxxorcat@users.noreply.github.com> Date: Fri Oct 6 16:04:39 2023 +0800 feat(google_drive): add `hash_info`, `ctime`, `thumbnail` (#5334) commit a008f54f4d5eda5738abfd54bf1abf1e18c08430 Author: nkh0472 <67589323+nkh0472@users.noreply.github.com> Date: Thu Oct 5 13:10:51 2023 +0800 docs: minor language improvements (#5329) [skip ci]
GoWebDAV
A golang WebDAV client library.
Main features
gowebdav
library allows to perform following actions on the remote WebDAV server:
- create path
- get files list
- download file
- upload file
- get information about specified file/folder
- move file to another location
- copy file to another location
- delete file
Usage
First of all you should create Client
instance using NewClient()
function:
root := "https://webdav.mydomain.me"
user := "user"
password := "password"
c := gowebdav.NewClient(root, user, password)
After you can use this Client
to perform actions, described below.
NOTICE: we will not check errors in examples, to focus you on the gowebdav
library's code, but you should do it in your code!
Create path on a WebDAV server
err := c.Mkdir("folder", 0644)
In case you want to create several folders you can use c.MkdirAll()
:
err := c.MkdirAll("folder/subfolder/subfolder2", 0644)
Get files list
files, _ := c.ReadDir("folder/subfolder")
for _, file := range files {
//notice that [file] has os.FileInfo type
fmt.Println(file.Name())
}
Download file to byte array
webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"
bytes, _ := c.Read(webdavFilePath)
ioutil.WriteFile(localFilePath, bytes, 0644)
Download file via reader
Also you can use c.ReadStream()
method:
webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"
reader, _ := c.ReadStream(webdavFilePath)
file, _ := os.Create(localFilePath)
defer file.Close()
io.Copy(file, reader)
Upload file from byte array
webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"
bytes, _ := ioutil.ReadFile(localFilePath)
c.Write(webdavFilePath, bytes, 0644)
Upload file via writer
webdavFilePath := "folder/subfolder/file.txt"
localFilePath := "/tmp/webdav/file.txt"
file, _ := os.Open(localFilePath)
defer file.Close()
c.WriteStream(webdavFilePath, file, 0644)
Get information about specified file/folder
webdavFilePath := "folder/subfolder/file.txt"
info := c.Stat(webdavFilePath)
//notice that [info] has os.FileInfo type
fmt.Println(info)
Move file to another location
oldPath := "folder/subfolder/file.txt"
newPath := "folder/subfolder/moved.txt"
isOverwrite := true
c.Rename(oldPath, newPath, isOverwrite)
Copy file to another location
oldPath := "folder/subfolder/file.txt"
newPath := "folder/subfolder/file-copy.txt"
isOverwrite := true
c.Copy(oldPath, newPath, isOverwrite)
Delete file
webdavFilePath := "folder/subfolder/file.txt"
c.Remove(webdavFilePath)
Links
More details about WebDAV server you can read from following resources:
- RFC 4918 - HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV)
- RFC 5689 - Extended MKCOL for Web Distributed Authoring and Versioning (WebDAV)
- RFC 2616 - HTTP/1.1 Status Code Definitions
- WebDav: Next Generation Collaborative Web Authoring By Lisa Dusseaul
NOTICE: RFC 2518 is obsoleted by RFC 4918 in June 2007
Contributing
All contributing are welcome. If you have any suggestions or find some bug - please create an Issue to let us make this project better. We appreciate your help!
License
This library is distributed under the BSD 3-Clause license found in the LICENSE file.
API
import "github.com/studio-b12/gowebdav"
Overview
Package gowebdav is a WebDAV client library with a command line tool included.
Index
- func FixSlash(s string) string
- func FixSlashes(s string) string
- func Join(path0 string, path1 string) string
- func PathEscape(path string) string
- func ReadConfig(uri, netrc string) (string, string)
- func String(r io.Reader) string
- type Authenticator
- type BasicAuth
- type Client
- func NewClient(uri, user, pw string) *Client
- func (c *Client) Connect() error
- func (c *Client) Copy(oldpath, newpath string, overwrite bool) error
- func (c *Client) Mkdir(path string, _ os.FileMode) error
- func (c *Client) MkdirAll(path string, _ os.FileMode) error
- func (c *Client) Read(path string) ([]byte, error)
- func (c *Client) ReadDir(path string) ([]os.FileInfo, error)
- func (c *Client) ReadStream(path string) (io.ReadCloser, error)
- func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error)
- func (c *Client) Remove(path string) error
- func (c *Client) RemoveAll(path string) error
- func (c *Client) Rename(oldpath, newpath string, overwrite bool) error
- func (c *Client) SetHeader(key, value string)
- func (c *Client) SetInterceptor(interceptor func(method string, rq *http.Request))
- func (c *Client) SetTimeout(timeout time.Duration)
- func (c *Client) SetTransport(transport http.RoundTripper)
- func (c *Client) Stat(path string) (os.FileInfo, error)
- func (c *Client) Write(path string, data []byte, _ os.FileMode) error
- func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error
- type DigestAuth
- type File
- func (f File) ContentType() string
- func (f File) ETag() string
- func (f File) IsDir() bool
- func (f File) ModTime() time.Time
- func (f File) Mode() os.FileMode
- func (f File) Name() string
- func (f File) Path() string
- func (f File) Size() int64
- func (f File) String() string
- func (f File) Sys() interface{}
- type NoAuth
Examples
Package files
basicAuth.go client.go digestAuth.go doc.go file.go netrc.go requests.go utils.go
func FixSlash
func FixSlash(s string) string
FixSlash appends a trailing / to our string
func FixSlashes
func FixSlashes(s string) string
FixSlashes appends and prepends a / if they are missing
func Join
func Join(path0 string, path1 string) string
Join joins two paths
func PathEscape
func PathEscape(path string) string
PathEscape escapes all segments of a given path
func ReadConfig
func ReadConfig(uri, netrc string) (string, string)
ReadConfig reads login and password configuration from ~/.netrc machine foo.com login username password 123456
func String
func String(r io.Reader) string
String pulls a string out of our io.Reader
type Authenticator
type Authenticator interface {
Type() string
User() string
Pass() string
Authorize(*http.Request, string, string)
}
Authenticator stub
type BasicAuth
type BasicAuth struct {
// contains filtered or unexported fields
}
BasicAuth structure holds our credentials
func (*BasicAuth) Authorize
func (b *BasicAuth) Authorize(req *http.Request, method string, path string)
Authorize the current request
func (*BasicAuth) Pass
func (b *BasicAuth) Pass() string
Pass holds the BasicAuth password
func (*BasicAuth) Type
func (b *BasicAuth) Type() string
Type identifies the BasicAuthenticator
func (*BasicAuth) User
func (b *BasicAuth) User() string
User holds the BasicAuth username
type Client
type Client struct {
// contains filtered or unexported fields
}
Client defines our structure
func NewClient
func NewClient(uri, user, pw string) *Client
NewClient creates a new instance of client
func (*Client) Connect
func (c *Client) Connect() error
Connect connects to our dav server
func (*Client) Copy
func (c *Client) Copy(oldpath, newpath string, overwrite bool) error
Copy copies a file from A to B
func (*Client) Mkdir
func (c *Client) Mkdir(path string, _ os.FileMode) error
Mkdir makes a directory
func (*Client) MkdirAll
func (c *Client) MkdirAll(path string, _ os.FileMode) error
MkdirAll like mkdir -p, but for webdav
func (*Client) Read
func (c *Client) Read(path string) ([]byte, error)
Read reads the contents of a remote file
func (*Client) ReadDir
func (c *Client) ReadDir(path string) ([]os.FileInfo, error)
ReadDir reads the contents of a remote directory
func (*Client) ReadStream
func (c *Client) ReadStream(path string) (io.ReadCloser, error)
ReadStream reads the stream for a given path
func (*Client) ReadStreamRange
func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error)
ReadStreamRange reads the stream representing a subset of bytes for a given path, utilizing HTTP Range Requests if the server supports it. The range is expressed as offset from the start of the file and length, for example offset=10, length=10 will return bytes 10 through 19.
If the server does not support partial content requests and returns full content instead,
this function will emulate the behavior by skipping offset
bytes and limiting the result
to length
.
func (*Client) Remove
func (c *Client) Remove(path string) error
Remove removes a remote file
func (*Client) RemoveAll
func (c *Client) RemoveAll(path string) error
RemoveAll removes remote files
func (*Client) Rename
func (c *Client) Rename(oldpath, newpath string, overwrite bool) error
Rename moves a file from A to B
func (*Client) SetHeader
func (c *Client) SetHeader(key, value string)
SetHeader lets us set arbitrary headers for a given client
func (*Client) SetInterceptor
func (c *Client) SetInterceptor(interceptor func(method string, rq *http.Request))
SetInterceptor lets us set an arbitrary interceptor for a given client
func (*Client) SetTimeout
func (c *Client) SetTimeout(timeout time.Duration)
SetTimeout exposes the ability to set a time limit for requests
func (*Client) SetTransport
func (c *Client) SetTransport(transport http.RoundTripper)
SetTransport exposes the ability to define custom transports
func (*Client) Stat
func (c *Client) Stat(path string) (os.FileInfo, error)
Stat returns the file stats for a specified path
func (*Client) Write
func (c *Client) Write(path string, data []byte, _ os.FileMode) error
Write writes data to a given path
func (*Client) WriteStream
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error
WriteStream writes a stream
type DigestAuth
type DigestAuth struct {
// contains filtered or unexported fields
}
DigestAuth structure holds our credentials
func (*DigestAuth) Authorize
func (d *DigestAuth) Authorize(req *http.Request, method string, path string)
Authorize the current request
func (*DigestAuth) Pass
func (d *DigestAuth) Pass() string
Pass holds the DigestAuth password
func (*DigestAuth) Type
func (d *DigestAuth) Type() string
Type identifies the DigestAuthenticator
func (*DigestAuth) User
func (d *DigestAuth) User() string
User holds the DigestAuth username
type File
type File struct {
// contains filtered or unexported fields
}
File is our structure for a given file
func (File) ContentType
func (f File) ContentType() string
ContentType returns the content type of a file
func (File) ETag
func (f File) ETag() string
ETag returns the ETag of a file
func (File) IsDir
func (f File) IsDir() bool
IsDir let us see if a given file is a directory or not
func (File) ModTime
func (f File) ModTime() time.Time
ModTime returns the modified time of a file
func (File) Mode
func (f File) Mode() os.FileMode
Mode will return the mode of a given file
func (File) Name
func (f File) Name() string
Name returns the name of a file
func (File) Path
func (f File) Path() string
Path returns the full path of a file
func (File) Size
func (f File) Size() int64
Size returns the size of a file
func (File) String
func (f File) String() string
String lets us see file information
func (File) Sys
func (f File) Sys() interface{}
Sys ????
type NoAuth
type NoAuth struct {
// contains filtered or unexported fields
}
NoAuth structure holds our credentials
func (*NoAuth) Authorize
func (n *NoAuth) Authorize(req *http.Request, method string, path string)
Authorize the current request
func (*NoAuth) Pass
func (n *NoAuth) Pass() string
Pass returns the current password
func (*NoAuth) Type
func (n *NoAuth) Type() string
Type identifies the authenticator
func (*NoAuth) User
func (n *NoAuth) User() string
User returns the current user
Generated by godoc2md