refactor: harden diagnostics and consolidate runtime code

This commit is contained in:
Mikhail Chusavitin
2026-09-01 13:01:28 +03:00
parent ac4bc0b2b7
commit 0a6ca8ba0f
49 changed files with 1441 additions and 837 deletions
+17
View File
@@ -348,6 +348,7 @@ func NewHandler(opts HandlerOptions) http.Handler {
mux.HandleFunc("POST /api/system/install-to-ram", h.handleAPIInstallToRAM)
mux.HandleFunc("POST /api/system/reboot", h.handleAPISystemReboot)
mux.HandleFunc("POST /api/system/shutdown", h.handleAPISystemShutdown)
mux.HandleFunc("GET /api/system/time", h.handleAPISystemTime)
mux.HandleFunc("POST /api/system/time-sync", h.handleAPISystemTimeSync)
// Preflight
@@ -813,3 +814,19 @@ func writeError(w http.ResponseWriter, status int, msg string) {
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(map[string]string{"error": msg})
}
func writeAPIListResponse[T any](w http.ResponseWriter, configured bool, load func() ([]T, error)) {
if !configured {
writeError(w, http.StatusServiceUnavailable, "app not configured")
return
}
items, err := load()
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
if items == nil {
items = []T{}
}
writeJSON(w, items)
}