I try to copy the value of a net.IP instance (line 14 and 19) but obviously just pass around the pointer:
http://play.golang.org/p/xmYQrsf496
What am I doing wrong?
CODE as requested:
package main
import (
"log"
"net"
)
type Range struct {
Start net.IP `json:"start"`
End net.IP `json:"end"`
}
func (r Range) Expand() []net.IP {
next := r.Start // here (line 14)
out := []net.IP{next}
for !next.Equal(r.End) {
incIP(next)
out = append(out, next) // and here (line 19)
}
return out
}
func incIP(ip net.IP) {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++
if ip[j] > 0 {
break
}
}
}
func main() {
r := Range{
Start: net.ParseIP("192.100.10.4"),
End: net.ParseIP("192.100.13.1"),
}
out := r.Expand()
log.Print(r)
log.Print(out)
}