refactor(models): typed Status constants with IsBroken() predicate
Replace ~150 bare status string comparisons with typed models.Status constants (StatusUp, StatusDown, StatusPending, StatusLate, StatusStale, StatusSSLExp). Single IsBroken() method replaces the duplicated isBroken lambda in monitor.go and isDown function in sla.go. Adding a new status value (e.g. DEGRADED) now requires one constant definition instead of grep-and-pray across 16 files. CheckResult.Status stays string — the checker is the boundary between raw protocol results and typed status. Cast happens at the edge in handleStatusChange.
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package models
|
||||
|
||||
type Status string
|
||||
|
||||
const (
|
||||
StatusUp Status = "UP"
|
||||
StatusDown Status = "DOWN"
|
||||
StatusPending Status = "PENDING"
|
||||
StatusLate Status = "LATE"
|
||||
StatusStale Status = "STALE"
|
||||
StatusSSLExp Status = "SSL EXP"
|
||||
)
|
||||
|
||||
func (s Status) IsBroken() bool {
|
||||
return s == StatusDown || s == StatusSSLExp
|
||||
}
|
||||
|
||||
func (s Status) String() string { return string(s) }
|
||||
Reference in New Issue
Block a user