feat: geo ip.

This commit is contained in:
tx7do
2023-10-19 15:27:32 +08:00
parent 01bdf5cc06
commit 7965576c1c
8 changed files with 73 additions and 34 deletions

View File

@@ -6,15 +6,11 @@ import (
"github.com/go-kratos/kratos/v2/log"
"github.com/oschwald/geoip2-golang"
"github.com/tx7do/kratos-utils/geoip"
"github.com/tx7do/kratos-utils/geoip/geolite/assets"
)
type Result struct {
Country string // 国家
Province string // 省
City string // 城市
}
const defaultOutputLanguage = "zh-CN"
// Client 地理位置解析结构体
@@ -56,7 +52,7 @@ func (g *Client) query(rawIP string) (city *geoip2.City, err error) {
}
// Query 通过IP获取地区
func (g *Client) Query(rawIP string) (ret Result, err error) {
func (g *Client) Query(rawIP string) (ret geoip.Result, err error) {
record, err := g.query(rawIP)
if err != nil {
log.Fatal(err)