feat: add heartbeat check for bug report API and enhance logging throughout the application

This commit is contained in:
Flavio Fois
2026-02-16 08:54:29 +01:00
parent 894e8d9e51
commit 828adcfcc2
15 changed files with 312 additions and 26 deletions

45
app_heartbeat.go Normal file
View File

@@ -0,0 +1,45 @@
// Package main provides heartbeat checking for the bug report API.
package main
import (
"fmt"
"net/http"
"time"
"emly/backend/utils"
)
// CheckBugReportAPI sends a GET request to the bug report API's /health
// endpoint with a short timeout. Returns true if the API responds with
// status 200, false otherwise. This is exposed to the frontend.
func (a *App) CheckBugReportAPI() bool {
cfgPath := utils.DefaultConfigPath()
cfg, err := utils.LoadConfig(cfgPath)
if err != nil {
Log("Heartbeat: failed to load config:", err)
return false
}
apiURL := cfg.EMLy.BugReportAPIURL
if apiURL == "" {
Log("Heartbeat: bug report API URL not configured")
return false
}
endpoint := apiURL + "/health"
client := &http.Client{Timeout: 3 * time.Second}
resp, err := client.Get(endpoint)
if err != nil {
Log("Heartbeat: API unreachable:", err)
return false
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
Log(fmt.Sprintf("Heartbeat: API returned status %d", resp.StatusCode))
return false
}
return true
}