platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func handleTransportClientHealthAction(w http.ResponseWriter, r *http.Request, id string) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
transportMu.Lock()
|
||||
st := loadTransportClientsState()
|
||||
transportMu.Unlock()
|
||||
idx := findTransportClientIndex(st.Items, id)
|
||||
if idx < 0 {
|
||||
writeJSON(w, http.StatusNotFound, TransportClientHealthResponse{
|
||||
OK: false,
|
||||
Message: "not found",
|
||||
Code: "TRANSPORT_CLIENT_NOT_FOUND",
|
||||
})
|
||||
return
|
||||
}
|
||||
it := st.Items[idx]
|
||||
now := time.Now().UTC()
|
||||
backend := selectTransportBackend(it)
|
||||
probe := backend.Health(it)
|
||||
snapshot := applyTransportHealthProbeSnapshot(it, backend.ID(), probe, now)
|
||||
resp := buildTransportHealthResponse(snapshot, now)
|
||||
if !probe.OK && strings.TrimSpace(probe.Code) != "" {
|
||||
resp.Code = probe.Code
|
||||
if strings.TrimSpace(probe.Message) != "" {
|
||||
resp.Message = probe.Message
|
||||
}
|
||||
}
|
||||
writeJSON(w, http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func handleTransportClientMetricsAction(w http.ResponseWriter, r *http.Request, id string) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
transportMu.Lock()
|
||||
st := loadTransportClientsState()
|
||||
transportMu.Unlock()
|
||||
idx := findTransportClientIndex(st.Items, id)
|
||||
if idx < 0 {
|
||||
writeJSON(w, http.StatusNotFound, TransportClientMetricsResponse{
|
||||
OK: false,
|
||||
Message: "not found",
|
||||
Code: "TRANSPORT_CLIENT_NOT_FOUND",
|
||||
})
|
||||
return
|
||||
}
|
||||
it := st.Items[idx]
|
||||
writeJSON(w, http.StatusOK, buildTransportMetricsResponse(it, time.Now().UTC()))
|
||||
}
|
||||
Reference in New Issue
Block a user