Files
rs_website/internal/status/status.go
Blake Ridgway 03fcf37beb first commit
2026-03-07 21:16:51 -06:00

47 lines
1.1 KiB
Go

// Package status loads and manages the service status JSON.
package status
import (
"encoding/json"
"os"
"time"
)
// Service represents a single monitored service.
type Service struct {
Name string `json:"name"`
Description string `json:"description"`
URL string `json:"url,omitempty"`
Status string `json:"status"` // "up", "degraded", "down", "unknown"
Note string `json:"note,omitempty"`
}
// Page is the full status page data loaded from JSON.
type Page struct {
LastChecked time.Time `json:"last_checked"`
Services []Service `json:"services"`
}
// Load reads and parses the status JSON from path.
func Load(path string) (*Page, error) {
raw, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var p Page
if err := json.Unmarshal(raw, &p); err != nil {
return nil, err
}
return &p, nil
}
// Save writes the status page data back to path.
func Save(path string, p *Page) error {
p.LastChecked = time.Now().UTC()
raw, err := json.MarshalIndent(p, "", " ")
if err != nil {
return err
}
return os.WriteFile(path, raw, 0644)
}