implement Remove
This commit is contained in:
parent
a5b6eb39ff
commit
d4b8ebb4b2
14
client.go
14
client.go
@ -117,6 +117,20 @@ func (c *Client) ReadDir(path string) ([]os.FileInfo, error) {
|
||||
return files, err
|
||||
}
|
||||
|
||||
func (c *Client) Remove(path string) error {
|
||||
rs, err := c.reqDo("DELETE", path, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rs.Body.Close()
|
||||
|
||||
if rs.StatusCode == 200 {
|
||||
return nil
|
||||
} else {
|
||||
return Error(rs)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Read(path string) {
|
||||
fmt.Println("Read " + path)
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func main() {
|
||||
root := flag.String("root", "URL", "WebDAV Endpoint")
|
||||
usr := flag.String("user", "", "user")
|
||||
pw := flag.String("pw", "", "password")
|
||||
m := flag.String("X", "GET", "Method: LIST aka PROPFIND, GET")
|
||||
m := flag.String("X", "GET", "Method: LIST aka PROPFIND, GET, DELETE")
|
||||
flag.Parse()
|
||||
|
||||
if *root == "URL" {
|
||||
@ -46,7 +46,14 @@ func main() {
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
case "GET": c.Read(path)
|
||||
|
||||
case "DELETE", "RM":
|
||||
if err := c.Remove(path); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
default: Fail(nil)
|
||||
}
|
||||
} else {
|
||||
|
@ -21,6 +21,15 @@ func (c *Client) req(method string, path string, body io.Reader) (req *http.Requ
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (c *Client) reqDo(method string, path string, body io.Reader) (*http.Response, error) {
|
||||
rq, err := c.req(method, path, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c.c.Do(rq)
|
||||
}
|
||||
|
||||
func (c *Client) Options(path string) (*http.Response, error) {
|
||||
rq, err := c.req("OPTIONS", path, nil)
|
||||
if err != nil {
|
||||
|
7
utils.go
7
utils.go
@ -3,12 +3,19 @@ package gowebdav
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Error(r *http.Response) error {
|
||||
return errors.New(fmt.Sprintf("%s - %s %s", r.Status, r.Request.Method, r.Request.URL.String()))
|
||||
}
|
||||
|
||||
func FixSlash(s string) string {
|
||||
if !strings.HasSuffix(s, "/") {
|
||||
s += "/"
|
||||
|
Loading…
Reference in New Issue
Block a user