refactor(core): remove store global singleton, thread store explicitly

Remove store.Get()/SetGlobal()/Current. Store is now passed explicitly
to all consumers via constructor parameters and function arguments.

- TUI Model holds store field, set via InitialModel(isAdmin, store)
- monitor.StartEngine(s) and InitHistoryFromStore(s) accept store
- server.Start(cfg, s) closes over store in HTTP handlers
- main.go threads store to SSH server, TUI, monitor, server
- isKeyAllowed receives store as parameter

No more hidden dependency on package-level mutable state in store pkg.
Monitor package still uses package-level state (LiveState, etc.) — will
be encapsulated into Engine struct in Phase 7.
This commit is contained in:
2026-05-15 00:45:07 -04:00
parent d4f4012c8a
commit a6bb9a7aff
9 changed files with 62 additions and 94 deletions
+8 -11
View File
@@ -4,7 +4,6 @@ import (
"fmt"
"go-upkeep/internal/models"
"go-upkeep/internal/monitor"
"go-upkeep/internal/store"
"net/url"
"strconv"
"strings"
@@ -361,14 +360,12 @@ func (m *Model) initSiteHuhForm() tea.Cmd {
}
alertOpts := []huh.Option[string]{huh.NewOption("None", "0")}
if s := store.Get(); s != nil {
if alerts, err := s.GetAllAlerts(); err == nil {
for _, a := range alerts {
alertOpts = append(alertOpts, huh.NewOption(
fmt.Sprintf("%s (%s)", a.Name, a.Type),
strconv.Itoa(a.ID),
))
}
if alerts, err := m.store.GetAllAlerts(); err == nil {
for _, a := range alerts {
alertOpts = append(alertOpts, huh.NewOption(
fmt.Sprintf("%s (%s)", a.Name, a.Type),
strconv.Itoa(a.ID),
))
}
}
@@ -560,12 +557,12 @@ func (m *Model) submitSiteForm() {
}
if m.editID > 0 {
if err := store.Get().UpdateSite(site); err != nil {
if err := m.store.UpdateSite(site); err != nil {
monitor.AddLog("Update site failed: " + err.Error())
}
monitor.UpdateSiteConfig(site)
} else {
if err := store.Get().AddSite(site); err != nil {
if err := m.store.AddSite(site); err != nil {
monitor.AddLog("Add site failed: " + err.Error())
}
}