diff --git a/README.md b/README.md index 93f2feb..de7881d 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,8 @@ Package gowebdav A golang WebDAV library * [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 File](#File) + * [func (f File) ContentType() string](#File.ContentType) + * [func (f File) ETag() string](#File.ETag) * [func (f File) IsDir() bool](#File.IsDir) * [func (f File) ModTime() time.Time](#File.ModTime) * [func (f File) Mode() os.FileMode](#File.Mode) @@ -133,55 +135,55 @@ 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=5825:5900#L279) +#### func (\*Client) [Copy](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6149:6224#L289) ``` go func (c *Client) Copy(oldpath string, 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=4909:4965#L238) +#### func (\*Client) [Mkdir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5233:5289#L248) ``` 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=5144:5203#L249) +#### func (\*Client) [MkdirAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5468:5527#L259) ``` 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=6006:6056#L284) +#### func (\*Client) [Read](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6330:6380#L294) ``` 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=2102:2162#L96) +#### func (\*Client) [ReadDir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=2240:2300#L98) ``` 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=6368:6431#L303) +#### func (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6692:6755#L313) ``` 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=4415:4457#L215) +#### func (\*Client) [Remove](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4739:4781#L225) ``` 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=4523:4568#L220) +#### func (\*Client) [RemoveAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4847:4892#L230) ``` 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=5652:5729#L274) +#### func (\*Client) [Rename](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5976:6053#L284) ``` go func (c *Client) Rename(oldpath string, newpath string, overwrite bool) error ``` @@ -205,25 +207,25 @@ 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=3430:3485#L163) +#### func (\*Client) [Stat](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=3661:3716#L169) ``` 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=6722:6791#L318) +#### func (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7046:7115#L328) ``` 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=7193:7273#L340) +#### func (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7517:7597#L350) ``` go func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error ``` WriteStream writes a stream -### type [File](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=93:198#L10) +### type [File](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=93:253#L10) ``` go type File struct { // contains filtered or unexported fields @@ -231,43 +233,55 @@ type File struct { ``` File is our structure for a given file -#### func (File) [IsDir](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=697:723#L44) +#### func (File) [ContentType](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=388:422#L26) +``` go +func (f File) ContentType() string +``` +ContentType returns the content type of a file + +#### func (File) [ETag](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=841:868#L51) +``` go +func (f File) ETag() string +``` +ETag returns the ETag of a file + +#### func (File) [IsDir](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=947:973#L56) ``` go func (f File) IsDir() bool ``` IsDir let us see if a given file is a directory or not -#### func (File) [ModTime](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=581:614#L39) +#### func (File) [ModTime](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=748:781#L46) ``` go func (f File) ModTime() time.Time ``` ModTime returns the modified time of a file -#### func (File) [Mode](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=410:442#L29) +#### func (File) [Mode](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=577:609#L36) ``` go func (f File) Mode() os.FileMode ``` Mode will return the mode of a given file -#### func (File) [Name](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=235:262#L19) +#### func (File) [Name](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=290:317#L21) ``` go func (f File) Name() string ``` Name returns the name of a file -#### func (File) [Size](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=318:344#L24) +#### func (File) [Size](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=485:511#L31) ``` go func (f File) Size() int64 ``` Size returns the size of a file -#### func (File) [String](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=845:874#L54) +#### func (File) [String](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=1095:1124#L66) ``` go func (f File) String() string ``` String lets us see file information -#### func (File) [Sys](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=757:788#L49) +#### func (File) [Sys](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=1007:1038#L61) ``` go func (f File) Sys() interface{} ``` diff --git a/client.go b/client.go index d471884..562971a 100644 --- a/client.go +++ b/client.go @@ -71,11 +71,13 @@ func (c *Client) Connect() error { } type props struct { - Status string `xml:"DAV: status"` - Name string `xml:"DAV: prop>displayname,omitempty"` - Type xml.Name `xml:"DAV: prop>resourcetype>collection,omitempty"` - Size string `xml:"DAV: prop>getcontentlength,omitempty"` - Modified string `xml:"DAV: prop>getlastmodified,omitempty"` + Status string `xml:"DAV: status"` + Name string `xml:"DAV: prop>displayname,omitempty"` + Type xml.Name `xml:"DAV: prop>resourcetype>collection,omitempty"` + Size string `xml:"DAV: prop>getcontentlength,omitempty"` + ContentType string `xml:"DAV: prop>getcontenttype,omitempty"` + ETag string `xml:"DAV: prop>getetag,omitempty"` + Modified string `xml:"DAV: prop>getlastmodified,omitempty"` } type response struct { @@ -118,6 +120,8 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) { } f.path = path + f.name f.modified = parseModified(&p.Modified) + f.etag = p.ETag + f.contentType = p.ContentType if p.Type.Local == "collection" { f.path += "/" @@ -141,6 +145,8 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) { + + `, @@ -168,6 +174,8 @@ func (c *Client) Stat(path string) (os.FileInfo, error) { f = new(File) f.name = p.Name f.path = path + f.etag = p.ETag + f.contentType = p.ContentType if p.Type.Local == "collection" { if !strings.HasSuffix(f.path, "/") { @@ -193,6 +201,8 @@ func (c *Client) Stat(path string) (os.FileInfo, error) { + + `, diff --git a/file.go b/file.go index 69ba799..200485d 100644 --- a/file.go +++ b/file.go @@ -8,11 +8,13 @@ import ( // File is our structure for a given file type File struct { - path string - name string - size int64 - modified time.Time - isdir bool + path string + name string + contentType string + size int64 + modified time.Time + etag string + isdir bool } // Name returns the name of a file @@ -20,6 +22,11 @@ func (f File) Name() string { return f.name } +// ContentType returns the content type of a file +func (f File) ContentType() string { + return f.contentType +} + // Size returns the size of a file func (f File) Size() int64 { return f.size @@ -40,6 +47,11 @@ func (f File) ModTime() time.Time { return f.modified } +// ETag returns the ETag of a file +func (f File) ETag() string { + return f.etag +} + // IsDir let us see if a given file is a directory or not func (f File) IsDir() bool { return f.isdir @@ -56,5 +68,5 @@ func (f File) String() string { return fmt.Sprintf("Dir : '%s' - '%s'", f.path, f.name) } - return fmt.Sprintf("File: '%s' SIZE: %d MODIFIED: %s", f.path, f.size, f.modified.String()) + return fmt.Sprintf("File: '%s' SIZE: %d MODIFIED: %s ETAG: %s CTYPE: %s", f.path, f.size, f.modified.String(), f.etag, f.contentType) }