From e15060b6f4142717eb8e21490f0c45ae6209c2f3 Mon Sep 17 00:00:00 2001 From: cya <2081215119@qq.com> Date: Fri, 24 May 2024 17:33:34 +0800 Subject: [PATCH] =?UTF-8?q?perf(validator):=20check=20Ipv4=E3=80=81Ipv6=20?= =?UTF-8?q?by=20more=20graceful=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- validator/validator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validator/validator.go b/validator/validator.go index 18150b2e..6c4811d1 100644 --- a/validator/validator.go +++ b/validator/validator.go @@ -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.