尝试将net.ip数组转换为https://golang.org/pkg/net/#IP.String
中定义的String rl, _ := nh.RouteList(nil,1)
// if err != nil {
// log.Fatal(err)
// }
for _, r := range rl {
updates = append( updates, Update{Route: r.Dst.String(), GW: r.Gw.String()})
fmt.Printf("Route %s\n", updates)
}
使用.String(),它似乎工作(呈现整个数组)没有.String()
root@ubuntu:/media/sf_gocode/src/github.com/alexanderturner/netnsplay# ./netnsplay -pid 8066
Loading routes for container: 8066
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x564d82bf31e2]
goroutine 1 [running]:
panic(0x564d82ca0ae0, 0xc82000e110)
/usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
net.networkNumberAndMask(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/usr/lib/go-1.6/src/net/ip.go:433 +0x42
net.(*IPNet).String(0x0, 0x0, 0x0)
/usr/lib/go-1.6/src/net/ip.go:483 +0x42
main.(*NSHandle).showInts(0xc820014260)
/media/sf_gocode/src/github.com/alexanderturner/netnsplay/netnsplay.go:46 +0xf8
main.main()
/media/sf_gocode/src/github.com/alexanderturner/netnsplay/netnsplay.go:98 +0xf1
root@ubuntu:/media/sf_gocode/src/github.com/alexanderturner/netnsplay#