Skip to content

Commit

Permalink
fix: ip2region city
Browse files Browse the repository at this point in the history
Signed-off-by: zu1k <i@lgf.im>
  • Loading branch information
zu1k committed Feb 20, 2022
1 parent 58e9ef6 commit fedbb96
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/ip2region/ip2region.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"strings"

"github.com/lionsoul2014/ip2region/binding/golang/ip2region"

Expand Down Expand Up @@ -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
}

0 comments on commit fedbb96

Please sign in to comment.