快速入门
下面以查询某个IPV4地址为例演示如何使用:
go.mod示例代码
module demo
go 1.14
main.go示例代码,lic和dex文件是我们通过阿里云控制台下载的离线库和授权文件
package main
import (
"fmt"
"log"
"demo/geoipclient"
)
func main() {
//client是线程安全,可以被多个goroutine使用
client, err := geoipclient.NewClient("20210222123044.lic", "20210310075715.dex")
if err != nil {
log.Println(err)
return
}
//查询
search := client.Search("221.206.131.10")
fmt.Println(search)
}
查结果如下:
{
"country": "中国",
"city": "牡丹江市",
"county_code": "231003",
"isp": "中国联通",
"province_en": "Heilongjiang",
"latitude": "44.596328",
"county": "阳明区",
"country_en": "China",
"city_code": "231000",
"province_code": "230000",
"city_en": "Mudanjiang",
"country_code": "CN",
"routes": "中国联通",
"province": "黑龙江省",
"isp_code": "100026",
"longitude": "129.634645"
}