aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go32
1 files changed, 32 insertions, 0 deletions
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)
+}