1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

perf(validator): check Ipv4、Ipv6 by more graceful method (#220)

This commit is contained in:
Cannian
2024-05-25 08:58:33 +08:00
committed by GitHub
parent e054680d20
commit 4b3a62b36a

View File

@@ -214,7 +214,7 @@ func IsIpV4(ipstr string) bool {
if ip == nil {
return false
}
return strings.Contains(ipstr, ".")
return ip.To4() != nil
}
// IsIpV6 check if the string is a ipv6 address.
@@ -224,7 +224,7 @@ func IsIpV6(ipstr string) bool {
if ip == nil {
return false
}
return strings.Contains(ipstr, ":")
return ip.To4() == nil && len(ip) == net.IPv6len
}
// IsPort check if the string is a valid net port.