go-webdav/cmd/webdav-server/main.go
2020-01-22 13:17:52 +01:00

33 lines
580 B
Go

package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"github.com/emersion/go-webdav"
)
func main() {
var addr string
flag.StringVar(&addr, "addr", ":8080", "listening address")
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "usage: %s [options...] [directory]\n", os.Args[0])
flag.PrintDefaults()
}
flag.Parse()
path := flag.Arg(0)
if path == "" {
path = "."
}
handler := webdav.Handler{
FileSystem: webdav.LocalFileSystem(path),
}
log.Printf("WebDAV server listening on %v", addr)
log.Fatal(http.ListenAndServe(addr, &handler))
}