优化代码

This commit is contained in:
刘祥超
2021-01-03 20:25:15 +08:00
parent 6b86ce1aef
commit 4d0764c3c2
36 changed files with 122 additions and 119 deletions

View File

@@ -0,0 +1,19 @@
package utils
import (
"encoding/binary"
"net"
)
// 将IP转换为整型
func IP2Long(ip string) uint32 {
s := net.ParseIP(ip)
if s == nil {
return 0
}
if len(s) == 16 {
return binary.BigEndian.Uint32(s[12:16])
}
return binary.BigEndian.Uint32(s)
}