// This file is part of the happyDomain (R) project. // Copyright (c) 2020-2026 happyDomain // Authors: Pierre-Olivier Mercier, et al. package checker import ( "sort" "sync" sdk "git.happydns.org/checker-sdk-go/checker" ) // registry holds the rules and collectors that ship with the checker. // Each rule/collector registers itself in an init() so that adding a new // one is a single-file change — no central list to maintain. var registry = struct { mu sync.Mutex rules []sdk.CheckRule collectors []Collector }{} // RegisterRule appends a rule to the global registry. Intended to be // called from init() in each rule file. func RegisterRule(r sdk.CheckRule) { registry.mu.Lock() defer registry.mu.Unlock() registry.rules = append(registry.rules, r) } // RegisterCollector appends a collector to the global registry. Reserved // for step 4; the orchestrator currently wires only rootCollector // directly. func RegisterCollector(c Collector) { registry.mu.Lock() defer registry.mu.Unlock() registry.collectors = append(registry.collectors, c) } // Rules returns every registered rule, sorted by Name() so the output is // stable across init-order changes (which Go does not guarantee between // files). func Rules() []sdk.CheckRule { registry.mu.Lock() out := make([]sdk.CheckRule, len(registry.rules)) copy(out, registry.rules) registry.mu.Unlock() sort.Slice(out, func(i, j int) bool { return out[i].Name() < out[j].Name() }) return out }