diff
diff copied to clipboard
net.IP comparable as String.
How do I force differ function so it would compare net.IP as a string and not as a slice?
https://go.dev/play/p/0VMlM5RQ9WO
package main
import (
"log"
"net"
"github.com/davecgh/go-spew/spew"
"github.com/r3labs/diff/v2"
)
type LoadBalancer struct {
IP []net.IP
}
func main() {
x := LoadBalancer{
IP: []net.IP{
net.ParseIP("192.0.2.1"),
net.ParseIP("192.0.2.2"),
},
}
y := LoadBalancer{
IP: []net.IP{
net.ParseIP("192.0.2.1"),
net.ParseIP("192.0.2.3"),
},
}
changelog, err := diff.Diff(x, y)
if err != nil {
log.Fatal(err)
}
spew.Dump(changelog)
}
(diff.Changelog) (len=1 cap=1) {
(diff.Change) {
Type: (string) (len=6) "update",
Path: ([]string) (len=3 cap=3) {
(string) (len=2) "IP",
(string) (len=1) "1",
(string) (len=2) "15"
},
From: (uint8) 2,
To: (uint8) 3,
parent: (interface {}) <nil>
}
}