d4f4012c8a
Every Store method now returns an error. Callers handle errors gracefully — TUI logs to event log, server returns HTTP 500, monitor engine logs and retries. All rows.Scan() errors are now checked in sqlstore.go instead of silently appending corrupt data. - GetSites, GetAllAlerts, GetAllUsers return ([]T, error) - GetAlert returns (AlertConfig, error) instead of (AlertConfig, bool) - AddSite, UpdateSite, DeleteSite, etc. all return error - SaveCheck, LoadAllHistory, ExportData return error - ~25 caller sites updated across tui, server, monitor, main
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package store
|
|
|
|
import (
|
|
"go-upkeep/internal/models"
|
|
)
|
|
|
|
type Store interface {
|
|
Init() error
|
|
|
|
// Sites
|
|
GetSites() ([]models.Site, error)
|
|
AddSite(site models.Site) error
|
|
UpdateSite(site models.Site) error
|
|
UpdateSitePaused(id int, paused bool) error
|
|
DeleteSite(id int) error
|
|
|
|
// Alerts
|
|
GetAllAlerts() ([]models.AlertConfig, error)
|
|
GetAlert(id int) (models.AlertConfig, error)
|
|
AddAlert(name, aType string, settings map[string]string) error
|
|
UpdateAlert(id int, name, aType string, settings map[string]string) error
|
|
DeleteAlert(id int) error
|
|
|
|
// Users
|
|
GetAllUsers() ([]models.User, error)
|
|
AddUser(username, publicKey, role string) error
|
|
UpdateUser(id int, username, publicKey, role string) error
|
|
DeleteUser(id int) error
|
|
|
|
// History
|
|
SaveCheck(siteID int, latencyNs int64, isUp bool) error
|
|
LoadAllHistory(limit int) (map[int][]models.CheckRecord, error)
|
|
|
|
// Backup & Restore
|
|
ExportData() (models.Backup, error)
|
|
ImportData(data models.Backup) error
|
|
}
|
|
|
|
var Current Store
|
|
|
|
func SetGlobal(s Store) {
|
|
Current = s
|
|
}
|
|
|
|
func Get() Store {
|
|
return Current
|
|
}
|