This commit is contained in:
Tordarus 2022-01-14 17:58:02 +01:00
parent 225fe84a6b
commit a4cb2922fa

18
main.go
View File

@ -27,14 +27,9 @@ var (
noauth = flag.Bool("a", false, "dont use basic auth")
)
var (
fileServer http.Handler
)
func main() {
flag.Parse()
fileServer = http.FileServer(http.Dir(""))
http.HandleFunc("/", handler)
dockerhealth.Healthy = true
@ -94,8 +89,14 @@ func get(w http.ResponseWriter, r *http.Request) {
return
}
r.URL.Path = path
fileServer.ServeHTTP(w, r)
file, err := os.Open(path)
if err != nil {
handleError(w, r, err)
return
}
defer file.Close()
io.Copy(w, file)
}
func put(w http.ResponseWriter, r *http.Request) {
@ -143,9 +144,6 @@ func head(w http.ResponseWriter, r *http.Request) {
w.Header().Add("File-Owner", username)
w.Header().Add("Group-Owner", groupname)
}
r.URL.Path = path
fileServer.ServeHTTP(w, r)
}
func delete(w http.ResponseWriter, r *http.Request) {