- Go module initialized with github.com/acty/pirate-station - HTTP server on port 32768 with root and health endpoints - Health check verifies /data volume mount - No external dependencies, stdlib only
29 lines
650 B
Go
29 lines
650 B
Go
package health
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
// Handler provides a health check endpoint that verifies the data volume is mounted
|
|
func Handler(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
// Check if /data directory exists
|
|
if _, err := os.Stat("/data"); os.IsNotExist(err) {
|
|
w.WriteHeader(http.StatusServiceUnavailable)
|
|
json.NewEncoder(w).Encode(map[string]string{
|
|
"status": "unhealthy",
|
|
"reason": "data volume not mounted",
|
|
})
|
|
return
|
|
}
|
|
|
|
// All checks passed
|
|
w.WriteHeader(http.StatusOK)
|
|
json.NewEncoder(w).Encode(map[string]string{
|
|
"status": "healthy",
|
|
})
|
|
}
|