package GeoIPUtil import ( "dsDataex/Utils/CacheUtil" "github.com/yinheli/qqwry" ) var DB *qqwry.QQwry var Province2260 map[string]string var City2260 map[string][]string func init() { //打开 纯真 IP离线库 DB = qqwry.NewQQwry("GeoLite2/qqwry.dat") //行政区划缓存 var sql = "SELECT area_code from t_dataex_gbt2260 where area_type=2 " var list,_,_=CacheUtil.Page(sql, 5000,0) Province2260=make( map[string]string) for no:=0;no< len(list);no++{ Province2260[list[no]["area_code"].(string)]=list[no]["area_name"].(string) } City2260=make( map[string][]string) for no:=0;no< len(list);no++{ City2260[list[no]["area_name"].(string)]=[]string{list[no]["area_code"].(string),list[no]["area_name"].(string),"",""} } sql = "SELECT area_code from t_dataex_gbt2260 where area_type=3 " list,_,_=CacheUtil.Page(sql, 5000,0) for no:=0;no< len(list);no++{ var provinceCode=list[no]["area_code"].(string)[0:2]+"0000" var provinceName=Province2260[provinceCode] City2260[provinceName+list[no]["area_name"].(string)]=[]string{provinceCode,provinceName,list[no]["area_code"].(string),list[no]["area_name"].(string)} } } func GetGeo4IP(temp string) []string { DB.Find(temp) //fmt.Println("qqwry :",DB.Country,DB.City) return City2260[DB.Country] }