Reduce API response size by using node ID references
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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 *)"
|
||||
|
||||
8
link.go
8
link.go
@@ -16,17 +16,17 @@ type Link struct {
|
||||
func (l *Link) MarshalJSON() ([]byte, error) {
|
||||
type linkJSON struct {
|
||||
ID string `json:"id"`
|
||||
NodeA interface{} `json:"node_a"`
|
||||
NodeAID string `json:"node_a_id"`
|
||||
InterfaceA string `json:"interface_a,omitempty"`
|
||||
NodeB interface{} `json:"node_b"`
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
37
types.go
37
types.go
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -368,6 +369,33 @@ type InterfaceStats struct {
|
||||
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 {
|
||||
Power float64 `json:"power"`
|
||||
MaxPower float64 `json:"max_power"`
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user