在各个地方支持IPv6

This commit is contained in:
GoEdgeLab
2021-07-20 10:55:52 +08:00
parent 4b11da6fcb
commit f5b88c955c
7 changed files with 97 additions and 49 deletions

View File

@@ -24,3 +24,17 @@ func IP2Long(ip string) uint64 {
}
return uint64(binary.BigEndian.Uint32(s.To4()))
}
// QuoteIP 为IPv6加上括号
func QuoteIP(ip string) string {
if len(ip) == 0 {
return ip
}
if !strings.Contains(ip, ":") {
return ip
}
if ip[0] != '[' {
return "[" + ip + "]"
}
return ip
}