Standardize codebase consistency: naming, JSON tags, logging, error wrapping

- JSON tags: fix snake_case to camelCase in dnsmasq (configFile, domainsConfigured,
  lastRestart), crowdsec Machine (lastPush, lastHeartbeat), network (primaryIP,
  primaryInterface). cscli raw parsing structs keep snake_case to match CLI output.
- Error wrapping: fix %v to %w in enableAuthelia for proper error chain preservation
- Naming: rename dnsmasq.ConfigGenerator to dnsmasq.Manager (matches all other packages),
  rename ServiceStatus to Status in dnsmasq and haproxy (matches authelia, crowdsec, etc.)
- Logging: standardize all slog calls to use "component" key instead of message prefixes.
  Affects reconcile, dnsfilter, ddns — now consistent with dnsmasq, haproxy, nftables, sse.
This commit is contained in:
2026-07-14 04:38:48 +00:00
parent 428d47f876
commit 3172e56288
13 changed files with 135 additions and 116 deletions

View File

@@ -315,7 +315,7 @@ func (m *Manager) UpdateLists(ctx context.Context) error {
continue
}
slog.Info("dns-filter: downloading list", "name", bl.Name, "url", bl.URL)
slog.Info("downloading list", "component", "dns-filter", "name", bl.Name, "url", bl.URL)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, bl.URL, nil)
if err != nil {
@@ -329,7 +329,7 @@ func (m *Manager) UpdateLists(ctx context.Context) error {
if err != nil {
bl.LastError = fmt.Sprintf("download failed: %v", err)
changed = true
slog.Warn("dns-filter: download failed", "name", bl.Name, "error", err)
slog.Warn("download failed", "component", "dns-filter", "name", bl.Name, "error", err)
continue
}
@@ -337,7 +337,7 @@ func (m *Manager) UpdateLists(ctx context.Context) error {
resp.Body.Close()
bl.LastError = fmt.Sprintf("HTTP %d", resp.StatusCode)
changed = true
slog.Warn("dns-filter: download failed", "name", bl.Name, "status", resp.StatusCode)
slog.Warn("download failed", "component", "dns-filter", "name", bl.Name, "status", resp.StatusCode)
continue
}
@@ -393,7 +393,7 @@ func (m *Manager) Compile() (int, error) {
domains, err := ParseFile(cachePath)
if err != nil {
slog.Warn("dns-filter: failed to parse list", "name", bl.Name, "error", err)
slog.Warn("failed to parse list", "component", "dns-filter", "name", bl.Name, "error", err)
continue
}
@@ -446,7 +446,7 @@ func (m *Manager) Compile() (int, error) {
// Update entry counts and save
_ = m.SaveFilterData(fd)
slog.Info("dns-filter: compiled blocklist", "domains", len(sorted))
slog.Info("compiled blocklist", "component", "dns-filter", "domains", len(sorted))
return len(sorted), nil
}
@@ -496,7 +496,7 @@ func (m *Manager) GetQueryStats() *QueryStats {
cmd := exec.Command("sudo", "journalctl", "-u", "dnsmasq", "--since", "24 hours ago", "--no-pager", "-o", "cat")
output, err := cmd.Output()
if err != nil {
slog.Debug("dns-filter: failed to read dnsmasq journal", "error", err)
slog.Debug("failed to read dnsmasq journal", "component", "dns-filter", "error", err)
return nil
}

View File

@@ -75,7 +75,7 @@ func (r *Runner) Trigger() {
func (r *Runner) run(ctx context.Context, intervalHours int) {
interval := time.Duration(intervalHours) * time.Hour
slog.Info("dns-filter: runner started", "interval", interval)
slog.Info("runner started", "component", "dns-filter", "interval", interval)
// Immediate update on start
r.updateAndCompile(ctx)
@@ -89,7 +89,7 @@ func (r *Runner) run(ctx context.Context, intervalHours int) {
r.mu.Lock()
r.running = false
r.mu.Unlock()
slog.Info("dns-filter: runner stopped")
slog.Info("runner stopped", "component", "dns-filter")
return
case <-ticker.C:
r.updateAndCompile(ctx)
@@ -101,11 +101,11 @@ func (r *Runner) run(ctx context.Context, intervalHours int) {
func (r *Runner) updateAndCompile(ctx context.Context) {
if err := r.manager.UpdateLists(ctx); err != nil {
slog.Error("dns-filter: update failed", "error", err)
slog.Error("update failed", "component", "dns-filter", "error", err)
}
if _, err := r.manager.Compile(); err != nil {
slog.Error("dns-filter: compile failed", "error", err)
slog.Error("compile failed", "component", "dns-filter", "error", err)
return
}