A library handling IP addresses like ipaddress-gem/ipaddress.
import (
"fmt"
"github.com/worbridg/ipaddress"
)
func main() {
ipv4, _ := ipaddress.NewIPv4Address("192.168.0.1/24")
fmt.Println(ipv4, ipv4.Network(), ipv4.Broadcast(), ipv4.IsPrivate(), ipv4.Netmask())
// Output: 192.168.0.1, 192.168.0.0, 192.168.0.255, true, 255.255.255.0
fmt.Println(ipv4.ARPA())
// Output: 1.0.168.192.in-addr.arpa
fmt.Println(ipv4.Sample(), ipv4.Sample())
// Output: 192.168.0.33, 192.168.0.199
}
$ go get github.com/worbridg/ipaddress
worbridg