From 6a384732e7d81d9bef6cad5300a8da8e96613e9c Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Sun, 30 Mar 2025 12:16:21 +0200 Subject: [PATCH] Better status response --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index cef4f0c..77cea96 100644 --- a/main.go +++ b/main.go @@ -44,6 +44,12 @@ type ResourceUsage struct { ActiveUsers int `json:"active_users"` } +type StatusResponse struct { + Usage ResourceUsage `json:"usage"` + Blockers []string `json:"blockers"` + Timestamp time.Time `json:"timestamp"` +} + var ( statusMutex sync.RWMutex blockers []string @@ -160,8 +166,14 @@ func handleStatus(w http.ResponseWriter, _ *http.Request) { statusMutex.RLock() defer statusMutex.RUnlock() + response := StatusResponse{ + Usage: currentStatus, + Blockers: blockers, + Timestamp: time.Now(), + } + w.Header().Set("Content-Type", "application/json") - err := json.NewEncoder(w).Encode(currentStatus) + err := json.NewEncoder(w).Encode(response) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) }