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 == "" {