Fetch ContentType and ETag
This commit is contained in:
parent
0120c3c3c4
commit
0e7fe90d28
54
README.md
54
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) 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) WriteStream(path string, stream io.Reader, _ os.FileMode) error](#Client.WriteStream)
|
||||||
* [type File](#File)
|
* [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) IsDir() bool](#File.IsDir)
|
||||||
* [func (f File) ModTime() time.Time](#File.ModTime)
|
* [func (f File) ModTime() time.Time](#File.ModTime)
|
||||||
* [func (f File) Mode() os.FileMode](#File.Mode)
|
* [func (f File) Mode() os.FileMode](#File.Mode)
|
||||||
@ -133,55 +135,55 @@ func (c *Client) Connect() error
|
|||||||
```
|
```
|
||||||
Connect connects to our dav server
|
Connect connects to our dav server
|
||||||
|
|
||||||
#### <a name="Client.Copy">func</a> (\*Client) [Copy](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5825:5900#L279)
|
#### <a name="Client.Copy">func</a> (\*Client) [Copy](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6149:6224#L289)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) Copy(oldpath string, newpath string, overwrite bool) error
|
func (c *Client) Copy(oldpath string, newpath string, overwrite bool) error
|
||||||
```
|
```
|
||||||
Copy copies a file from A to B
|
Copy copies a file from A to B
|
||||||
|
|
||||||
#### <a name="Client.Mkdir">func</a> (\*Client) [Mkdir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4909:4965#L238)
|
#### <a name="Client.Mkdir">func</a> (\*Client) [Mkdir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5233:5289#L248)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) Mkdir(path string, _ os.FileMode) error
|
func (c *Client) Mkdir(path string, _ os.FileMode) error
|
||||||
```
|
```
|
||||||
Mkdir makes a directory
|
Mkdir makes a directory
|
||||||
|
|
||||||
#### <a name="Client.MkdirAll">func</a> (\*Client) [MkdirAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5144:5203#L249)
|
#### <a name="Client.MkdirAll">func</a> (\*Client) [MkdirAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5468:5527#L259)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) MkdirAll(path string, _ os.FileMode) error
|
func (c *Client) MkdirAll(path string, _ os.FileMode) error
|
||||||
```
|
```
|
||||||
MkdirAll like mkdir -p, but for webdav
|
MkdirAll like mkdir -p, but for webdav
|
||||||
|
|
||||||
#### <a name="Client.Read">func</a> (\*Client) [Read](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6006:6056#L284)
|
#### <a name="Client.Read">func</a> (\*Client) [Read](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6330:6380#L294)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) Read(path string) ([]byte, error)
|
func (c *Client) Read(path string) ([]byte, error)
|
||||||
```
|
```
|
||||||
Read reads the contents of a remote file
|
Read reads the contents of a remote file
|
||||||
|
|
||||||
#### <a name="Client.ReadDir">func</a> (\*Client) [ReadDir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=2102:2162#L96)
|
#### <a name="Client.ReadDir">func</a> (\*Client) [ReadDir](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=2240:2300#L98)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) ReadDir(path string) ([]os.FileInfo, error)
|
func (c *Client) ReadDir(path string) ([]os.FileInfo, error)
|
||||||
```
|
```
|
||||||
ReadDir reads the contents of a remote directory
|
ReadDir reads the contents of a remote directory
|
||||||
|
|
||||||
#### <a name="Client.ReadStream">func</a> (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6368:6431#L303)
|
#### <a name="Client.ReadStream">func</a> (\*Client) [ReadStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6692:6755#L313)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) ReadStream(path string) (io.ReadCloser, error)
|
func (c *Client) ReadStream(path string) (io.ReadCloser, error)
|
||||||
```
|
```
|
||||||
ReadStream reads the stream for a given path
|
ReadStream reads the stream for a given path
|
||||||
|
|
||||||
#### <a name="Client.Remove">func</a> (\*Client) [Remove](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4415:4457#L215)
|
#### <a name="Client.Remove">func</a> (\*Client) [Remove](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4739:4781#L225)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) Remove(path string) error
|
func (c *Client) Remove(path string) error
|
||||||
```
|
```
|
||||||
Remove removes a remote file
|
Remove removes a remote file
|
||||||
|
|
||||||
#### <a name="Client.RemoveAll">func</a> (\*Client) [RemoveAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4523:4568#L220)
|
#### <a name="Client.RemoveAll">func</a> (\*Client) [RemoveAll](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=4847:4892#L230)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) RemoveAll(path string) error
|
func (c *Client) RemoveAll(path string) error
|
||||||
```
|
```
|
||||||
RemoveAll removes remote files
|
RemoveAll removes remote files
|
||||||
|
|
||||||
#### <a name="Client.Rename">func</a> (\*Client) [Rename](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5652:5729#L274)
|
#### <a name="Client.Rename">func</a> (\*Client) [Rename](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=5976:6053#L284)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) Rename(oldpath string, newpath string, overwrite bool) error
|
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
|
SetTransport exposes the ability to define custom transports
|
||||||
|
|
||||||
#### <a name="Client.Stat">func</a> (\*Client) [Stat](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=3430:3485#L163)
|
#### <a name="Client.Stat">func</a> (\*Client) [Stat](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=3661:3716#L169)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) Stat(path string) (os.FileInfo, error)
|
func (c *Client) Stat(path string) (os.FileInfo, error)
|
||||||
```
|
```
|
||||||
Stat returns the file stats for a specified path
|
Stat returns the file stats for a specified path
|
||||||
|
|
||||||
#### <a name="Client.Write">func</a> (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=6722:6791#L318)
|
#### <a name="Client.Write">func</a> (\*Client) [Write](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7046:7115#L328)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) Write(path string, data []byte, _ os.FileMode) error
|
func (c *Client) Write(path string, data []byte, _ os.FileMode) error
|
||||||
```
|
```
|
||||||
Write writes data to a given path
|
Write writes data to a given path
|
||||||
|
|
||||||
#### <a name="Client.WriteStream">func</a> (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7193:7273#L340)
|
#### <a name="Client.WriteStream">func</a> (\*Client) [WriteStream](https://github.com/studio-b12/gowebdav/blob/master/client.go?s=7517:7597#L350)
|
||||||
``` go
|
``` go
|
||||||
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error
|
func (c *Client) WriteStream(path string, stream io.Reader, _ os.FileMode) error
|
||||||
```
|
```
|
||||||
WriteStream writes a stream
|
WriteStream writes a stream
|
||||||
|
|
||||||
### <a name="File">type</a> [File](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=93:198#L10)
|
### <a name="File">type</a> [File](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=93:253#L10)
|
||||||
``` go
|
``` go
|
||||||
type File struct {
|
type File struct {
|
||||||
// contains filtered or unexported fields
|
// contains filtered or unexported fields
|
||||||
@ -231,43 +233,55 @@ type File struct {
|
|||||||
```
|
```
|
||||||
File is our structure for a given file
|
File is our structure for a given file
|
||||||
|
|
||||||
#### <a name="File.IsDir">func</a> (File) [IsDir](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=697:723#L44)
|
#### <a name="File.ContentType">func</a> (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
|
||||||
|
|
||||||
|
#### <a name="File.ETag">func</a> (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
|
||||||
|
|
||||||
|
#### <a name="File.IsDir">func</a> (File) [IsDir](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=947:973#L56)
|
||||||
``` go
|
``` go
|
||||||
func (f File) IsDir() bool
|
func (f File) IsDir() bool
|
||||||
```
|
```
|
||||||
IsDir let us see if a given file is a directory or not
|
IsDir let us see if a given file is a directory or not
|
||||||
|
|
||||||
#### <a name="File.ModTime">func</a> (File) [ModTime](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=581:614#L39)
|
#### <a name="File.ModTime">func</a> (File) [ModTime](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=748:781#L46)
|
||||||
``` go
|
``` go
|
||||||
func (f File) ModTime() time.Time
|
func (f File) ModTime() time.Time
|
||||||
```
|
```
|
||||||
ModTime returns the modified time of a file
|
ModTime returns the modified time of a file
|
||||||
|
|
||||||
#### <a name="File.Mode">func</a> (File) [Mode](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=410:442#L29)
|
#### <a name="File.Mode">func</a> (File) [Mode](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=577:609#L36)
|
||||||
``` go
|
``` go
|
||||||
func (f File) Mode() os.FileMode
|
func (f File) Mode() os.FileMode
|
||||||
```
|
```
|
||||||
Mode will return the mode of a given file
|
Mode will return the mode of a given file
|
||||||
|
|
||||||
#### <a name="File.Name">func</a> (File) [Name](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=235:262#L19)
|
#### <a name="File.Name">func</a> (File) [Name](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=290:317#L21)
|
||||||
``` go
|
``` go
|
||||||
func (f File) Name() string
|
func (f File) Name() string
|
||||||
```
|
```
|
||||||
Name returns the name of a file
|
Name returns the name of a file
|
||||||
|
|
||||||
#### <a name="File.Size">func</a> (File) [Size](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=318:344#L24)
|
#### <a name="File.Size">func</a> (File) [Size](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=485:511#L31)
|
||||||
``` go
|
``` go
|
||||||
func (f File) Size() int64
|
func (f File) Size() int64
|
||||||
```
|
```
|
||||||
Size returns the size of a file
|
Size returns the size of a file
|
||||||
|
|
||||||
#### <a name="File.String">func</a> (File) [String](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=845:874#L54)
|
#### <a name="File.String">func</a> (File) [String](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=1095:1124#L66)
|
||||||
``` go
|
``` go
|
||||||
func (f File) String() string
|
func (f File) String() string
|
||||||
```
|
```
|
||||||
String lets us see file information
|
String lets us see file information
|
||||||
|
|
||||||
#### <a name="File.Sys">func</a> (File) [Sys](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=757:788#L49)
|
#### <a name="File.Sys">func</a> (File) [Sys](https://github.com/studio-b12/gowebdav/blob/master/file.go?s=1007:1038#L61)
|
||||||
``` go
|
``` go
|
||||||
func (f File) Sys() interface{}
|
func (f File) Sys() interface{}
|
||||||
```
|
```
|
||||||
|
10
client.go
10
client.go
@ -75,6 +75,8 @@ type props struct {
|
|||||||
Name string `xml:"DAV: prop>displayname,omitempty"`
|
Name string `xml:"DAV: prop>displayname,omitempty"`
|
||||||
Type xml.Name `xml:"DAV: prop>resourcetype>collection,omitempty"`
|
Type xml.Name `xml:"DAV: prop>resourcetype>collection,omitempty"`
|
||||||
Size string `xml:"DAV: prop>getcontentlength,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"`
|
Modified string `xml:"DAV: prop>getlastmodified,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +120,8 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
|||||||
}
|
}
|
||||||
f.path = path + f.name
|
f.path = path + f.name
|
||||||
f.modified = parseModified(&p.Modified)
|
f.modified = parseModified(&p.Modified)
|
||||||
|
f.etag = p.ETag
|
||||||
|
f.contentType = p.ContentType
|
||||||
|
|
||||||
if p.Type.Local == "collection" {
|
if p.Type.Local == "collection" {
|
||||||
f.path += "/"
|
f.path += "/"
|
||||||
@ -141,6 +145,8 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
|||||||
<d:displayname/>
|
<d:displayname/>
|
||||||
<d:resourcetype/>
|
<d:resourcetype/>
|
||||||
<d:getcontentlength/>
|
<d:getcontentlength/>
|
||||||
|
<d:getcontenttype/>
|
||||||
|
<d:getetag/>
|
||||||
<d:getlastmodified/>
|
<d:getlastmodified/>
|
||||||
</d:prop>
|
</d:prop>
|
||||||
</d:propfind>`,
|
</d:propfind>`,
|
||||||
@ -168,6 +174,8 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
|
|||||||
f = new(File)
|
f = new(File)
|
||||||
f.name = p.Name
|
f.name = p.Name
|
||||||
f.path = path
|
f.path = path
|
||||||
|
f.etag = p.ETag
|
||||||
|
f.contentType = p.ContentType
|
||||||
|
|
||||||
if p.Type.Local == "collection" {
|
if p.Type.Local == "collection" {
|
||||||
if !strings.HasSuffix(f.path, "/") {
|
if !strings.HasSuffix(f.path, "/") {
|
||||||
@ -193,6 +201,8 @@ func (c *Client) Stat(path string) (os.FileInfo, error) {
|
|||||||
<d:displayname/>
|
<d:displayname/>
|
||||||
<d:resourcetype/>
|
<d:resourcetype/>
|
||||||
<d:getcontentlength/>
|
<d:getcontentlength/>
|
||||||
|
<d:getcontenttype/>
|
||||||
|
<d:getetag/>
|
||||||
<d:getlastmodified/>
|
<d:getlastmodified/>
|
||||||
</d:prop>
|
</d:prop>
|
||||||
</d:propfind>`,
|
</d:propfind>`,
|
||||||
|
14
file.go
14
file.go
@ -10,8 +10,10 @@ import (
|
|||||||
type File struct {
|
type File struct {
|
||||||
path string
|
path string
|
||||||
name string
|
name string
|
||||||
|
contentType string
|
||||||
size int64
|
size int64
|
||||||
modified time.Time
|
modified time.Time
|
||||||
|
etag string
|
||||||
isdir bool
|
isdir bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +22,11 @@ func (f File) Name() string {
|
|||||||
return f.name
|
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
|
// Size returns the size of a file
|
||||||
func (f File) Size() int64 {
|
func (f File) Size() int64 {
|
||||||
return f.size
|
return f.size
|
||||||
@ -40,6 +47,11 @@ func (f File) ModTime() time.Time {
|
|||||||
return f.modified
|
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
|
// IsDir let us see if a given file is a directory or not
|
||||||
func (f File) IsDir() bool {
|
func (f File) IsDir() bool {
|
||||||
return f.isdir
|
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("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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user