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:
@@ -155,7 +155,7 @@ func (rn *Runner) checkAndUpdate() {
|
||||
|
||||
p := rn.paramsFn()
|
||||
if p.APIToken == "" || len(p.Records) == 0 {
|
||||
slog.Debug("DDNS: no token or records, skipping", "component", "ddns")
|
||||
slog.Debug("no token or records, skipping", "component", "ddns")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -164,11 +164,11 @@ func (rn *Runner) checkAndUpdate() {
|
||||
rn.mu.Lock()
|
||||
rn.status.LastError = fmt.Sprintf("getting public IP: %v", err)
|
||||
rn.mu.Unlock()
|
||||
slog.Error("DDNS: failed to get public IP", "component", "ddns", "error", err)
|
||||
slog.Error("failed to get public IP", "component", "ddns", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
slog.Debug("DDNS: syncing records", "component", "ddns", "ip", ip, "records", p.Records)
|
||||
slog.Debug("syncing records", "component", "ddns", "ip", ip, "records", p.Records)
|
||||
|
||||
cf := &cfClient{apiToken: p.APIToken}
|
||||
|
||||
@@ -177,7 +177,7 @@ func (rn *Runner) checkAndUpdate() {
|
||||
for _, record := range p.Records {
|
||||
if err := cf.updateRecord(record, ip); err != nil {
|
||||
lastErr = fmt.Sprintf("updating %s: %v", record, err)
|
||||
slog.Error("DDNS: failed to update record", "component", "ddns", "record", record, "error", err)
|
||||
slog.Error("failed to update record", "component", "ddns", "record", record, "error", err)
|
||||
records = append(records, RecordStatus{Name: record, OK: false, Error: err.Error()})
|
||||
} else {
|
||||
records = append(records, RecordStatus{Name: record, IP: ip, OK: true})
|
||||
@@ -304,13 +304,13 @@ func (c *cfClient) updateRecord(recordName, ip string) error {
|
||||
|
||||
// No A record. Remove any CNAME that would conflict.
|
||||
if cnameID, _, cnameErr := c.getRecordID(zoneID, recordName, "CNAME"); cnameErr == nil {
|
||||
slog.Info("DDNS: removing CNAME before creating A record", "component", "ddns", "record", recordName)
|
||||
slog.Info("removing CNAME before creating A record", "component", "ddns", "record", recordName)
|
||||
if err := c.deleteRecord(zoneID, cnameID); err != nil {
|
||||
return fmt.Errorf("removing CNAME for %s: %w", recordName, err)
|
||||
}
|
||||
}
|
||||
|
||||
slog.Info("DDNS: creating A record", "component", "ddns", "record", recordName)
|
||||
slog.Info("creating A record", "component", "ddns", "record", recordName)
|
||||
return c.createRecord(zoneID, recordName, ip)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user