在各个地方支持IPv6

This commit is contained in:
刘祥超
2021-07-20 10:55:52 +08:00
parent b9e01b7738
commit a241b9a9df
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
}