Omit empty ips arrays from interface JSON

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ian Gulliver
2026-01-30 10:09:17 -08:00
parent 9a39802de9
commit 71e9337bdb

View File

@@ -354,10 +354,29 @@ func (m InterfaceMap) MarshalJSON() ([]byte, error) {
type Interface struct {
Name string `json:"name,omitempty"`
MAC MAC `json:"mac"`
IPs IPSet `json:"ips"`
IPs IPSet `json:"ips,omitempty"`
Stats *InterfaceStats `json:"stats,omitempty"`
}
func (i *Interface) MarshalJSON() ([]byte, error) {
type ifaceJSON struct {
Name string `json:"name,omitempty"`
MAC MAC `json:"mac"`
IPs []string `json:"ips,omitempty"`
Stats *InterfaceStats `json:"stats,omitempty"`
}
var ips []string
if len(i.IPs) > 0 {
ips = i.IPs.Slice()
}
return json.Marshal(ifaceJSON{
Name: i.Name,
MAC: i.MAC,
IPs: ips,
Stats: i.Stats,
})
}
type InterfaceStats struct {
Speed uint64 `json:"speed,omitempty"`
InErrors uint64 `json:"in_errors,omitempty"`