Make healthz endpoint verify upload directory is accessible

This commit is contained in:
2026-08-29 00:45:41 +02:00
parent b774e23ac0
commit 5817269855
+10
View File
@@ -107,6 +107,7 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
return
}
if r.Method == "GET" && r.URL.Path == "/healthz" {
handleHealthz(w, r)
return
}
@@ -133,6 +134,15 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
logRequest(r, 405, time.Since(start))
}
func handleHealthz(w http.ResponseWriter, r *http.Request) {
if _, err := os.Stat(uploadDir); err != nil {
log.Printf("Healthz check failed: %v", err)
http.Error(w, "Upload directory is not accessible", http.StatusServiceUnavailable)
return
}
w.WriteHeader(http.StatusOK)
}
func handleUpload(w http.ResponseWriter, r *http.Request, start time.Time) {
filename := strings.TrimPrefix(r.URL.Path, "/")
if filename == "" {