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:
@@ -12,8 +12,8 @@ import (
|
||||
type Machine struct {
|
||||
MachineID string `json:"machineId"`
|
||||
IsValidated bool `json:"isValidated"`
|
||||
LastPush string `json:"last_push,omitempty"`
|
||||
LastHeartbeat string `json:"last_heartbeat,omitempty"`
|
||||
LastPush string `json:"lastPush,omitempty"`
|
||||
LastHeartbeat string `json:"lastHeartbeat,omitempty"`
|
||||
IPAddress string `json:"ipAddress,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
@@ -104,10 +104,29 @@ func (m *Manager) GetMachines() ([]Machine, error) {
|
||||
if out == "" || out == "null" {
|
||||
return []Machine{}, nil
|
||||
}
|
||||
var machines []Machine
|
||||
if err := json.Unmarshal([]byte(out), &machines); err != nil {
|
||||
// cscli outputs snake_case JSON — map to our camelCase API types
|
||||
var raw []struct {
|
||||
MachineID string `json:"machineId"`
|
||||
IsValidated bool `json:"isValidated"`
|
||||
LastPush string `json:"last_push"`
|
||||
LastHeartbeat string `json:"last_heartbeat"`
|
||||
IPAddress string `json:"ipAddress"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(out), &raw); err != nil {
|
||||
return nil, fmt.Errorf("parsing machines: %w", err)
|
||||
}
|
||||
machines := make([]Machine, 0, len(raw))
|
||||
for _, r := range raw {
|
||||
machines = append(machines, Machine{
|
||||
MachineID: r.MachineID,
|
||||
IsValidated: r.IsValidated,
|
||||
LastPush: r.LastPush,
|
||||
LastHeartbeat: r.LastHeartbeat,
|
||||
IPAddress: r.IPAddress,
|
||||
Version: r.Version,
|
||||
})
|
||||
}
|
||||
return machines, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user