server/cmd/noah-server/noah-server.go

30 lines
684 B
Go

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