2026-05-26 12:21:39 +05:30
|
|
|
package doctor
|
|
|
|
|
|
|
|
|
|
type CheckStatus int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
StatusPass CheckStatus = iota
|
|
|
|
|
StatusWarn
|
|
|
|
|
StatusFail
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CheckResult struct {
|
2026-07-14 21:34:22 +05:30
|
|
|
Name string
|
|
|
|
|
Category string
|
|
|
|
|
Status CheckStatus
|
|
|
|
|
Message string
|
|
|
|
|
ImpliesInterception bool
|
|
|
|
|
// Fix overrides the check's static fix hint for this specific result.
|
|
|
|
|
Fix string
|
2026-05-26 12:21:39 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Check struct {
|
|
|
|
|
Name string
|
|
|
|
|
Category string
|
|
|
|
|
Run func() CheckResult
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RunChecks(checks []Check) []CheckResult {
|
|
|
|
|
results := make([]CheckResult, 0, len(checks))
|
|
|
|
|
for _, c := range checks {
|
|
|
|
|
result := c.Run()
|
|
|
|
|
result.Name = c.Name
|
|
|
|
|
result.Category = c.Category
|
|
|
|
|
results = append(results, result)
|
|
|
|
|
}
|
|
|
|
|
return results
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func HasFailures(results []CheckResult) bool {
|
|
|
|
|
for _, r := range results {
|
|
|
|
|
if r.Status == StatusFail {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CategorySummary(results []CheckResult) map[string]CheckStatus {
|
|
|
|
|
summary := make(map[string]CheckStatus)
|
|
|
|
|
for _, r := range results {
|
|
|
|
|
current, exists := summary[r.Category]
|
|
|
|
|
if !exists || r.Status > current {
|
|
|
|
|
summary[r.Category] = r.Status
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return summary
|
|
|
|
|
}
|