30 lines
688 B
Go
30 lines
688 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"golang.org/x/net/webdav"
|
|
)
|
|
|
|
func main() {
|
|
fs := &webdav.Handler{
|
|
FileSystem: webdav.Dir("."),
|
|
LockSystem: webdav.NewMemLS(),
|
|
}
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Println(r.Method, r.URL.Path)
|
|
username, password, ok := r.BasicAuth()
|
|
if !ok {
|
|
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
return
|
|
}
|
|
if username != "username" || password != "password" {
|
|
http.Error(w, "WebDAV: need authorized!", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
fs.ServeHTTP(w, r)
|
|
})
|
|
fmt.Println("wait requests")
|
|
http.ListenAndServe(":8080", nil)
|
|
} |