-
-
Notifications
You must be signed in to change notification settings - Fork 175
/
main.go
57 lines (46 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"net/http"
"os"
"strings"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/accesslog"
"github.com/kataras/iris/v12/middleware/recover"
"golang.org/x/net/webdav"
)
func main() {
app := iris.New()
app.Logger().SetLevel("debug")
app.Use(recover.New())
app.Use(accesslog.New(os.Stdout).Handler)
webdavHandler := &webdav.Handler{
FileSystem: webdav.Dir("./"),
LockSystem: webdav.NewMemLS(),
Logger: func(r *http.Request, err error) {
if err != nil {
app.Logger().Error(err)
}
},
}
app.HandleMany(strings.Join(iris.WebDAVMethods, " "), "/{p:path}", iris.FromStd(webdavHandler))
app.Listen(":8080",
iris.WithoutServerError(iris.ErrServerClosed, iris.ErrURLQuerySemicolon),
iris.WithoutPathCorrection,
)
}
/* Test with cURL or postman:
* List files:
curl --location --request PROPFIND 'http://localhost:8080'
* Get File:
curl --location --request GET 'http://localhost:8080/test.txt'
* Upload File:
curl --location --request PUT 'http://localhost:8080/newfile.txt' \
--header 'Content-Type: text/plain' \
--data-raw 'This is a new file!'
* Copy File:
curl --location --request COPY 'http://localhost:8080/test.txt' \
--header 'Destination: newdir/test.txt'
* Create New Directory:
curl --location --request MKCOL 'http://localhost:8080/anewdir/'
And e.t.c.
*/