From 5817269855fae9537cb50bca77dbdb8f39e61216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sat, 29 Aug 2026 00:45:41 +0200 Subject: [PATCH] Make healthz endpoint verify upload directory is accessible --- main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.go b/main.go index 114db42..c9df7a7 100644 --- a/main.go +++ b/main.go @@ -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 == "" {