package notify import ( "fmt" "time" "vetting/internal/config" ) // BuildRegistry translates the config surface into a live Registry. // Unknown notifier types produce an error so typos fail startup loudly // rather than silently drop events. func BuildRegistry(notifiers []config.Notifier, routes []config.Route) (*Registry, error) { reg := NewRegistry(10 * time.Second) for _, n := range notifiers { switch n.Type { case "": continue // skip blank entries; useful for commented-out examples case "ntfy": reg.Register(NewNtfy(n.Name, n.Server, n.Topic)) case "discord": reg.Register(NewDiscord(n.Name, n.WebhookURL)) case "smtp": reg.Register(NewSMTP(n.Name, n.SMTP.Host, n.SMTP.Port, n.SMTP.From, n.SMTP.To)) default: return nil, fmt.Errorf("notify: unknown notifier type %q (name=%q)", n.Type, n.Name) } } for _, r := range routes { if r.Notifier == "" { return nil, fmt.Errorf("notify: route has no notifier name") } reg.AddRoute(Route{ MatchKind: toKinds(r.MatchKind), MatchSeverity: toSeverities(r.MatchSeverity), Notifier: r.Notifier, }) } return reg, nil } func toKinds(ss []string) []Kind { out := make([]Kind, 0, len(ss)) for _, s := range ss { out = append(out, Kind(s)) } return out } func toSeverities(ss []string) []Severity { out := make([]Severity, 0, len(ss)) for _, s := range ss { out = append(out, Severity(s)) } return out }