Omit empty ips arrays from interface JSON
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
21
types.go
21
types.go
@@ -354,10 +354,29 @@ func (m InterfaceMap) MarshalJSON() ([]byte, error) {
|
|||||||
type Interface struct {
|
type Interface struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
MAC MAC `json:"mac"`
|
MAC MAC `json:"mac"`
|
||||||
IPs IPSet `json:"ips"`
|
IPs IPSet `json:"ips,omitempty"`
|
||||||
Stats *InterfaceStats `json:"stats,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 {
|
type InterfaceStats struct {
|
||||||
Speed uint64 `json:"speed,omitempty"`
|
Speed uint64 `json:"speed,omitempty"`
|
||||||
InErrors uint64 `json:"in_errors,omitempty"`
|
InErrors uint64 `json:"in_errors,omitempty"`
|
||||||
|
|||||||
Reference in New Issue
Block a user