Files
bl/common/utils/qqwry/qqwry_test.go

33 lines
583 B
Go
Raw Normal View History

package qqwry
import (
"testing"
)
func init() {
if err := LoadFile("assets/qqwry.ipdb"); err != nil {
panic(err)
}
}
func TestQueryIP(t *testing.T) {
queryIp := "119.29.29.29"
location, err := QueryIP(queryIp)
if err != nil {
t.Fatal(err)
}
emptyVal := func(val string) string {
if val != "" {
return val
}
return "未知"
}
t.Logf("国家:%s省份%s城市%s区县%s运营商%s",
emptyVal(location.Country),
emptyVal(location.Province),
emptyVal(location.City),
emptyVal(location.District),
emptyVal(location.ISP),
)
}