mirror of https://github.com/rocboss/paopao-ce
parent
e82db3ef6b
commit
8b33f6ac3c
@ -1,12 +1,8 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import "github.com/rocboss/paopao-ce/pkg/util/iploc"
|
||||||
"github.com/yinheli/qqwry"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetIPLoc(ip string) string {
|
func GetIPLoc(ip string) string {
|
||||||
q := qqwry.NewQQwry("qqwry.dat")
|
country, _ := iploc.Find(ip)
|
||||||
q.Find(ip)
|
return country
|
||||||
|
|
||||||
return q.Country
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package iploc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFind(t *testing.T) {
|
||||||
|
for _, data := range []struct {
|
||||||
|
ip string
|
||||||
|
country string
|
||||||
|
city string
|
||||||
|
}{
|
||||||
|
{ip: "127.0.0.1", country: "本机地址", city: " CZ88.NET"},
|
||||||
|
{ip: "180.89.94.9", country: "北京市", city: "鹏博士宽带"},
|
||||||
|
} {
|
||||||
|
country, city := Find(data.ip)
|
||||||
|
t.Logf("ip:%v, country:%v, city:%v", data.ip, country, city)
|
||||||
|
if country != data.country {
|
||||||
|
t.Errorf("find ip:%s expect country: %s got: %s", data.ip, data.country, country)
|
||||||
|
}
|
||||||
|
if city != data.city {
|
||||||
|
t.Errorf("find ip:%s expect city: %s got: %s", data.ip, data.city, city)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue