2 Star 3 Fork 0

yongfu / ip4region

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ip4region_util.go 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
liaoyongfu 提交于 2021-01-12 09:19 . update pkg ip4region
package ip4region
import (
"strings"
)
func (ip IPInfo) String() string {
return ip.Country + "|" + ip.Region + "|" + ip.Province + "|" + ip.City + "|" + ip.ISP
}
func getIPInfo(line []byte) IPInfo {
lineSlice := strings.Split(string(line), "|")
ipInfo := IPInfo{}
length := len(lineSlice)
//ipInfo.CityId = cityId
if length < 5 {
for i := 0; i <= 5-length; i++ {
lineSlice = append(lineSlice, "")
}
}
ipInfo.Country = lineSlice[0]
ipInfo.Region = lineSlice[1]
ipInfo.Province = lineSlice[2]
ipInfo.City = lineSlice[3]
ipInfo.ISP = lineSlice[4]
return ipInfo
}
func getLong(b []byte, offset int64) int64 {
val := (int64(b[offset])<<24 |
int64(b[offset+1])<<16 |
int64(b[offset+2])<<8 |
int64(b[offset+3]))
return val
}
func (ip4 *IP4Region) getLong(offset int64) int64 {
val := (int64(ip4.dbBinStr[offset])<<24 |
int64(ip4.dbBinStr[offset+1])<<16 |
int64(ip4.dbBinStr[offset+2])<<8 |
int64(ip4.dbBinStr[offset+3]))
return val
}
func getLongLitte(b []byte, offset int64) int64 {
val := (int64(b[offset]) |
int64(b[offset+1])<<8 |
int64(b[offset+2])<<16 |
int64(b[offset+3])<<24)
return val
}
func (ip4 *IP4Region) getLongLitte(offset int64) int64 {
val := (int64(ip4.dbBinStr[offset]) |
int64(ip4.dbBinStr[offset+1])<<8 |
int64(ip4.dbBinStr[offset+2])<<16 |
int64(ip4.dbBinStr[offset+3])<<24)
return val
}
Go
1
https://gitee.com/RickieL/ip4region.git
git@gitee.com:RickieL/ip4region.git
RickieL
ip4region
ip4region
v1.0.1

搜索帮助