Skip to content

Commit

Permalink
perf(validator): check Ipv4、Ipv6 by more graceful method (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
cannian1 authored May 25, 2024
1 parent e054680 commit 4b3a62b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 4b3a62b

Please sign in to comment.