💩 优化 CountryCode 获取

This commit is contained in:
naiba
2022-03-31 22:59:07 +08:00
parent 1f051459bb
commit 888f2efa60
3 changed files with 25 additions and 13 deletions

View File

@@ -17,14 +17,16 @@ func TestGeoIPApi(t *testing.T) {
assert.Nil(t, err)
resp.Body.Close()
var ip geoIP
err = utils.Json.Unmarshal(body, &ip)
err = ip.Unmarshal(body)
assert.Nil(t, err)
t.Logf("%s %s %s %s", geoIPApiList[i], ip.CountryCode, utils.IPDesensitize(ip.IP), utils.IPDesensitize(ip.Query))
assert.True(t, ip.IP != "" || ip.Query != "")
t.Logf("%s %s %s", geoIPApiList[i], ip.CountryCode, utils.IPDesensitize(ip.IP))
assert.True(t, ip.IP != "")
assert.True(t, ip.CountryCode != "")
}
}
func TestFetchGeoIP(t *testing.T) {
ip := fetchGeoIP(geoIPApiList, false)
assert.NotEmpty(t, ip.IP)
assert.NotEmpty(t, ip.CountryCode)
}