jimt’s answer is correct, but fairly complicated. I would simply check ip.To4() != nil
. Since the documentation says “if ip is not an IPv4 address, To4 returns nil” this condition should return true
if and only if the address is an IPv4 address.
jimt’s answer is correct, but fairly complicated. I would simply check ip.To4() != nil
. Since the documentation says “if ip is not an IPv4 address, To4 returns nil” this condition should return true
if and only if the address is an IPv4 address.