ip := net.ParseIP("192.168.0.1").To4() if ip == nil { // invalid IPv4 address } else { // use the IP address }
ip := net.IPv4(192, 168, 0, 1) bytes := ip.To4()
ip := net.ParseIP("::1") if ip.To4() == nil { // not an IPv4 address } else { // is an IPv4 address }Overall, the net.IPv4() function is used to create and manipulate IPv4 addresses in Go.