diff --git a/.claude/settings.local.json b/.claude/settings.local.json index f291d18..dfdcd16 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -72,7 +72,22 @@ "Bash(git -C /home/flamingcow/artmap diff)", "Bash(git -C /home/flamingcow/artnet status)", "Bash(git -C /home/flamingcow/tendrils status)", - "Bash(git -C /home/flamingcow/artmap status)" + "Bash(git -C /home/flamingcow/artmap status)", + "Bash(git -C /home/flamingcow/artnet status --short)", + "Bash(git -C /home/flamingcow/tendrils status --short)", + "Bash(git -C /home/flamingcow/artmap status --short)", + "Bash(git -C /home/flamingcow/sacn status --short)", + "Bash(git -C /home/flamingcow/multicast status --short)", + "Bash(git -C /home/flamingcow/artnet diff go.mod go.sum)", + "Bash(git -C /home/flamingcow/tendrils diff go.mod go.sum)", + "Bash(git -C /home/flamingcow/artmap diff go.mod go.sum)", + "Bash(git -C /home/flamingcow/sacn diff go.mod go.sum)", + "Bash(git -C /home/flamingcow/multicast diff go.mod go.sum)", + "Bash(git -C /home/flamingcow/artnet diff --name-only)", + "Bash(git -C /home/flamingcow/tendrils diff --name-only)", + "Bash(git -C /home/flamingcow/artmap diff --name-only)", + "Bash(git -C /home/flamingcow/sacn diff --name-only)", + "Bash(git -C /home/flamingcow/multicast diff --name-only)" ], "ask": [ "Bash(rm *)" diff --git a/link.go b/link.go index 7256825..4be2cf1 100644 --- a/link.go +++ b/link.go @@ -15,18 +15,18 @@ type Link struct { func (l *Link) MarshalJSON() ([]byte, error) { type linkJSON struct { - ID string `json:"id"` - NodeA interface{} `json:"node_a"` - InterfaceA string `json:"interface_a,omitempty"` - NodeB interface{} `json:"node_b"` - InterfaceB string `json:"interface_b,omitempty"` + ID string `json:"id"` + NodeAID string `json:"node_a_id"` + InterfaceA string `json:"interface_a,omitempty"` + NodeBID string `json:"node_b_id"` + InterfaceB string `json:"interface_b,omitempty"` } return json.Marshal(linkJSON{ ID: l.ID, - NodeA: l.NodeA.WithInterface(l.InterfaceA), + NodeAID: l.NodeA.ID, InterfaceA: l.InterfaceA, - NodeB: l.NodeB.WithInterface(l.InterfaceB), + NodeBID: l.NodeB.ID, InterfaceB: l.InterfaceB, }) } diff --git a/types.go b/types.go index 43efb11..db5a2f0 100644 --- a/types.go +++ b/types.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "math" "net" "sort" "strings" @@ -358,14 +359,41 @@ type Interface struct { } type InterfaceStats struct { - Speed uint64 `json:"speed,omitempty"` - InErrors uint64 `json:"in_errors,omitempty"` - OutErrors uint64 `json:"out_errors,omitempty"` - InPktsRate float64 `json:"in_pkts_rate,omitempty"` - OutPktsRate float64 `json:"out_pkts_rate,omitempty"` - InBytesRate float64 `json:"in_bytes_rate,omitempty"` - OutBytesRate float64 `json:"out_bytes_rate,omitempty"` - PoE *PoEStats `json:"poe,omitempty"` + Speed uint64 `json:"speed,omitempty"` + InErrors uint64 `json:"in_errors,omitempty"` + OutErrors uint64 `json:"out_errors,omitempty"` + InPktsRate float64 `json:"in_pkts_rate,omitempty"` + OutPktsRate float64 `json:"out_pkts_rate,omitempty"` + InBytesRate float64 `json:"in_bytes_rate,omitempty"` + OutBytesRate float64 `json:"out_bytes_rate,omitempty"` + PoE *PoEStats `json:"poe,omitempty"` +} + +func round2(v float64) float64 { + return math.Round(v*100) / 100 +} + +func (s *InterfaceStats) MarshalJSON() ([]byte, error) { + type statsJSON struct { + Speed uint64 `json:"speed,omitempty"` + InErrors uint64 `json:"in_errors,omitempty"` + OutErrors uint64 `json:"out_errors,omitempty"` + InPktsRate float64 `json:"in_pkts_rate,omitempty"` + OutPktsRate float64 `json:"out_pkts_rate,omitempty"` + InBytesRate float64 `json:"in_bytes_rate,omitempty"` + OutBytesRate float64 `json:"out_bytes_rate,omitempty"` + PoE *PoEStats `json:"poe,omitempty"` + } + return json.Marshal(statsJSON{ + Speed: s.Speed, + InErrors: s.InErrors, + OutErrors: s.OutErrors, + InPktsRate: round2(s.InPktsRate), + OutPktsRate: round2(s.OutPktsRate), + InBytesRate: round2(s.InBytesRate), + OutBytesRate: round2(s.OutBytesRate), + PoE: s.PoE, + }) } type PoEStats struct { @@ -558,16 +586,11 @@ type DantePeer struct { func (p *DantePeer) MarshalJSON() ([]byte, error) { type peerJSON struct { - Node *Node `json:"node"` + NodeID string `json:"node_id"` Channels []*DanteChannel `json:"channels,omitempty"` } - nodeRef := &Node{ - ID: p.Node.ID, - Names: p.Node.Names, - Interfaces: p.Node.Interfaces, - } return json.Marshal(peerJSON{ - Node: nodeRef, + NodeID: p.Node.ID, Channels: p.Channels, }) }