package main import ( "log" "net/http" "os" "golang.org/x/net/webdav" ) const ( envPrefix = "WEBDAV_PREFIX" pathRoot = "/webdav/root" pathLog = "/dev/stdout" ) func logger() func(*http.Request, error) { return func(r *http.Request, err error) { if err != nil { log.Printf("ERROR %v\n", err) } } } func filesystem() webdav.FileSystem { if err := os.Mkdir(pathRoot, os.ModePerm); !os.IsExist(err) { log.Fatalf("FATAL %v", err) } log.Printf("INFO using local filesystem at %s", pathRoot) return webdav.Dir(pathRoot) } func main() { logFile, err := os.OpenFile(pathLog, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { log.Fatalf("FATAL %v", err) } defer logFile.Close() log.SetOutput(logFile) h := &webdav.Handler{ Prefix: os.Getenv(envPrefix), FileSystem: filesystem(), LockSystem: webdav.NewMemLS(), Logger: logger(), } http.HandleFunc("/", h.ServeHTTP) http.ListenAndServe(":8080", h) }