From fedbb96901e7ccab9d820eafd10c6fd27e38334c Mon Sep 17 00:00:00 2001 From: zu1k Date: Sun, 20 Feb 2022 11:41:26 +0800 Subject: [PATCH] fix: ip2region city Signed-off-by: zu1k --- pkg/ip2region/ip2region.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/ip2region/ip2region.go b/pkg/ip2region/ip2region.go index 29e0b8e..fb46c31 100644 --- a/pkg/ip2region/ip2region.go +++ b/pkg/ip2region/ip2region.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "strings" "github.com/lionsoul2014/ip2region/binding/golang/ip2region" @@ -40,11 +41,20 @@ func (db Ip2Region) Find(query string, params ...string) (result fmt.Stringer, e return nil, err } - fmt.Println(ip) + area := "" + if ip.Province != "0" { + area = ip.Province + } + if ip.City != "0" && strings.EqualFold(ip.City, ip.Province) { + area = area + " " + ip.Province + } + if ip.ISP != "0" { + area = area + " " + ip.ISP + } result = common.Result{ Country: ip.Country, - Area: ip.Province, + Area: area, } return result, nil }