diff options
| author | Marin Ivanov <[email protected]> | 2024-02-05 14:54:55 +0200 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2024-02-05 14:54:55 +0200 |
| commit | f316c889db7337f5ff43d2e876f1229bd3dcee8c (patch) | |
| tree | 7aaaae3c4bc0933f2a919249675194f1e22b3462 | |
Initial commit
| -rw-r--r-- | go.mod | 8 | ||||
| -rw-r--r-- | go.sum | 4 | ||||
| -rw-r--r-- | main.go | 32 |
3 files changed, 44 insertions, 0 deletions
@@ -0,0 +1,8 @@ +module go.metala.org/webdav + +go 1.21.5 + +require ( + github.com/spf13/pflag v1.0.5 + golang.org/x/net v0.20.0 +) @@ -0,0 +1,4 @@ +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= +golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= @@ -0,0 +1,32 @@ +package main + +import ( + "golang.org/x/net/webdav" + "log" + "net/http" + "path/filepath" + + flag "github.com/spf13/pflag" +) + +func main() { + var ( + bind string + rootDir string + ) + flag.StringVarP(&bind, "bind", "b", "localhost:8080", "Address to listen to.") + flag.StringVarP(&rootDir, "root", "r", ".", "Address to listen to.") + flag.Parse() + + handler := &webdav.Handler{ + FileSystem: webdav.Dir(rootDir), + LockSystem: webdav.NewMemLS(), + } + + root, err := filepath.Abs(rootDir) + if err != nil { + log.Fatalf("Invalid path '%s': %s", rootDir, err) + } + log.Printf("Starting WebDAV server at '%s' on '%s'...", root, bind) + http.ListenAndServe(bind, handler) +} |
