aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod8
-rw-r--r--go.sum4
-rw-r--r--main.go32
3 files changed, 44 insertions, 0 deletions
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..c28c798
--- /dev/null
+++ b/go.mod
@@ -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
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..9bb197b
--- /dev/null
+++ b/go.sum
@@ -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=
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..501a5ad
--- /dev/null
+++ b/main.go
@@ -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)
+}