Make healthz endpoint verify upload directory is accessible
This commit is contained in:
@@ -107,6 +107,7 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if r.Method == "GET" && r.URL.Path == "/healthz" {
|
if r.Method == "GET" && r.URL.Path == "/healthz" {
|
||||||
|
handleHealthz(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,6 +134,15 @@ func handleRequest(w http.ResponseWriter, r *http.Request) {
|
|||||||
logRequest(r, 405, time.Since(start))
|
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) {
|
func handleUpload(w http.ResponseWriter, r *http.Request, start time.Time) {
|
||||||
filename := strings.TrimPrefix(r.URL.Path, "/")
|
filename := strings.TrimPrefix(r.URL.Path, "/")
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user