Just increment the last octet in the IP address
ip := net.ParseIP("127.1.0.0")
ip = ip.To4()
ip[3]++
fmt.Println(ip)
This, however, is technically incorrect, since the first address on the 127.1.0.1/8 subnet is 127.0.0.1. To get the true "first" address, you will also need IPMask. Since you did not specify one, you can use DefaultMask for IPv4 addresses (for IPv6 you cannot accept a mask, and you must provide it).
http://play.golang.org/p/P_QWwRIBIm
ip := net.IP{192, 168, 1, 10}
ip = ip.To4()
if ip == nil {
log.Fatal("non ipv4 address")
}
ip = ip.Mask(ip.DefaultMask())
ip[3]++
fmt.Println(ip)
//192.168.1.1
source
share