38 lines
704 B
Go
38 lines
704 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"golang.org/x/net/webdav"
|
|
"log"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type Handler struct {
|
|
webdav.Handler
|
|
}
|
|
|
|
func (h *Handler)ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
switch r.Method {
|
|
case "GET", "HEAD":
|
|
if strings.HasSuffix(r.URL.Path, "/") {
|
|
r.URL.Path += "index.html"
|
|
}
|
|
}
|
|
h.Handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
|
|
func main() {
|
|
address := flag.String("a", ":8080", "Address to listen to")
|
|
directory := flag.String("d", ".", "Directory to serve")
|
|
flag.Parse()
|
|
|
|
handler := &Handler{}
|
|
handler.FileSystem = webdav.Dir(*directory)
|
|
handler.LockSystem = webdav.NewMemLS()
|
|
|
|
log.Println("Listening on", *address)
|
|
http.ListenAndServe(*address, handler)
|
|
}
|