From a8ff76ef65bac1e204d354d1a0beef36585489e6 Mon Sep 17 00:00:00 2001 From: txthinking Date: Sat, 4 May 2024 22:34:17 +0800 Subject: [PATCH] bugfix --- cli/brook/main.go | 6 +++--- go.mod | 2 +- go.sum | 2 ++ list.go | 5 ++--- test_test.go | 6 ++++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cli/brook/main.go b/cli/brook/main.go index ba05c8be..f4968ac8 100644 --- a/cli/brook/main.go +++ b/cli/brook/main.go @@ -2742,11 +2742,11 @@ func main() { if ip == nil { return errors.New(c.String("ip") + " is not IP") } - b := iploc.Country(ip) - if b == nil { + s := iploc.Country(ip) + if s == "" { return errors.New(c.String("ip") + " unknown") } - fmt.Println(string(b)) + fmt.Println(s) return nil }, }, diff --git a/go.mod b/go.mod index cc626eff..61776bbd 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/krolaw/dhcp4 v0.0.0-20190909130307-a50d88189771 github.com/miekg/dns v1.1.57 github.com/patrickmn/go-cache v2.1.0+incompatible - github.com/phuslu/iploc v1.0.20231031 + github.com/phuslu/iploc v1.0.20240501 github.com/prometheus/client_golang v1.17.0 github.com/quic-go/quic-go v0.42.0 github.com/refraction-networking/utls v1.5.4 diff --git a/go.sum b/go.sum index 32d26e63..d1d598df 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/phuslu/iploc v1.0.20231031 h1:AsKT2PqStXV+gqJjNJ5mcUJ7YT9i09W+NVthhz5987s= github.com/phuslu/iploc v1.0.20231031/go.mod h1:gsgExGWldwv1AEzZm+Ki9/vGfyjkL33pbSr9HGpt2Xg= +github.com/phuslu/iploc v1.0.20240501 h1:lX2dEFOQzxVpTH3dgJ+pcNEpLxwaJUhoCGMoajuAI5w= +github.com/phuslu/iploc v1.0.20240501/go.mod h1:VZqAWoi2A80YPvfk1AizLGHavNIG9nhBC8d87D/SeVs= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= diff --git a/list.go b/list.go index a364e9b8..f821ea3d 100644 --- a/list.go +++ b/list.go @@ -71,9 +71,8 @@ func ListHasIP(c4, c6 []*net.IPNet, i net.IP, c *cache.Cache, geo []string) bool } } if len(geo) != 0 { - b := iploc.Country(i) - if b != nil { - bs := string(b) + bs := iploc.Country(i) + if bs != "" { for _, v := range geo { if v == bs { if c != nil { diff --git a/test_test.go b/test_test.go index 40b49f3e..ff135644 100644 --- a/test_test.go +++ b/test_test.go @@ -16,10 +16,12 @@ package brook import ( "log" + "net" "testing" + + "github.com/phuslu/iploc" ) func TestTest(t *testing.T) { - l, err := CAC("/tmp/a") - log.Printf("%#v %v\n", l, err) + log.Printf("%#v\n", iploc.Country(net.ParseIP("8.8.8.8"))) }