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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user