-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathmain.go
50 lines (44 loc) · 1.31 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
package main
import (
"fmt"
"net/http"
_115 "github.com/gaoyb7/115drive-webdav/115"
"github.com/gaoyb7/115drive-webdav/common/config"
"github.com/gaoyb7/115drive-webdav/webdav"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
var (
cfg = config.Config
)
func main() {
logrus.SetReportCaller(true)
webdavHandler := webdav.Handler{
DriveClient: _115.MustNew115DriveClient(cfg.Uid, cfg.Cid, cfg.Seid),
LockSystem: webdav.NewMemLS(),
Logger: func(req *http.Request, err error) {
if err != nil {
logrus.WithField("method", req.Method).WithField("path", req.URL.Path).Errorf("err: %v", err)
}
},
}
webdavHandleFunc := func(c *gin.Context) {
webdavHandler.ServeHTTP(c.Writer, c.Request)
}
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
dav := r.Group("", gin.BasicAuth(gin.Accounts{
cfg.User: cfg.Password,
}))
dav.Any("/*path", webdavHandleFunc)
dav.Handle("PROPFIND", "/*path", webdavHandleFunc)
dav.Handle("MKCOL", "/*path", webdavHandleFunc)
dav.Handle("LOCK", "/*path", webdavHandleFunc)
dav.Handle("UNLOCK", "/*path", webdavHandleFunc)
dav.Handle("PROPPATCH", "/*path", webdavHandleFunc)
dav.Handle("COPY", "/*path", webdavHandleFunc)
dav.Handle("MOVE", "/*path", webdavHandleFunc)
if err := r.Run(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)); err != nil {
logrus.Panic(err)
}
}