mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-14 09:42:28 +08:00
perf(validator): check Ipv4、Ipv6 by more graceful method (#220)
This commit is contained in:
@@ -214,7 +214,7 @@ func IsIpV4(ipstr string) bool {
|
|||||||
if ip == nil {
|
if ip == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return strings.Contains(ipstr, ".")
|
return ip.To4() != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsIpV6 check if the string is a ipv6 address.
|
// IsIpV6 check if the string is a ipv6 address.
|
||||||
@@ -224,7 +224,7 @@ func IsIpV6(ipstr string) bool {
|
|||||||
if ip == nil {
|
if ip == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return strings.Contains(ipstr, ":")
|
return ip.To4() == nil && len(ip) == net.IPv6len
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsPort check if the string is a valid net port.
|
// IsPort check if the string is a valid net port.
|
||||||
|
|||||||
Reference in New Issue
Block a user