Fix IP deduplication and filter link interfaces in JSON

This commit is contained in:
Ian Gulliver
2026-01-25 09:53:31 -08:00
parent 3a33ece7d9
commit 4c149ecdf7
3 changed files with 45 additions and 1 deletions

23
link.go
View File

@@ -1,6 +1,9 @@
package tendrils
import "fmt"
import (
"encoding/json"
"fmt"
)
type Link struct {
TypeID string `json:"typeid"`
@@ -10,6 +13,24 @@ type Link struct {
InterfaceB string `json:"interface_b,omitempty"`
}
func (l *Link) MarshalJSON() ([]byte, error) {
type linkJSON struct {
TypeID string `json:"typeid"`
NodeA interface{} `json:"node_a"`
InterfaceA string `json:"interface_a,omitempty"`
NodeB interface{} `json:"node_b"`
InterfaceB string `json:"interface_b,omitempty"`
}
return json.Marshal(linkJSON{
TypeID: l.TypeID,
NodeA: l.NodeA.WithInterface(l.InterfaceA),
InterfaceA: l.InterfaceA,
NodeB: l.NodeB.WithInterface(l.InterfaceB),
InterfaceB: l.InterfaceB,
})
}
func (l *Link) String() string {
nameA := l.NodeA.DisplayName()
if nameA == "" {