mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-10 03:03:44 +08:00
模块化上传驱动,使用泛型优化工具库降低冗余
This commit is contained in:
@@ -72,20 +72,19 @@ func WhoisLocation(ctx context.Context, ip string) (*IpLocationData, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var whoisData *WhoisRegionData
|
||||
if err = gconv.Struct([]byte(str), &whoisData); err != nil {
|
||||
var who *WhoisRegionData
|
||||
if err = gconv.Struct([]byte(str), &who); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IpLocationData{
|
||||
Ip: whoisData.Ip,
|
||||
Region: whoisData.Addr,
|
||||
Province: whoisData.Pro,
|
||||
ProvinceCode: gconv.Int64(whoisData.ProCode),
|
||||
City: whoisData.City,
|
||||
CityCode: gconv.Int64(whoisData.CityCode),
|
||||
Area: whoisData.Region,
|
||||
AreaCode: gconv.Int64(whoisData.RegionCode),
|
||||
Ip: who.Ip,
|
||||
Region: who.Addr,
|
||||
Province: who.Pro,
|
||||
ProvinceCode: gconv.Int64(who.ProCode),
|
||||
City: who.City,
|
||||
CityCode: gconv.Int64(who.CityCode),
|
||||
Area: who.Region,
|
||||
AreaCode: gconv.Int64(who.RegionCode),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -159,7 +158,6 @@ func GetLocation(ctx context.Context, ip string) (data *IpLocationData, err erro
|
||||
}
|
||||
cacheMap.Set(ip, data)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -234,6 +232,5 @@ func GetClientIp(r *ghttp.Request) string {
|
||||
if gstr.Contains(ip, ", ") {
|
||||
ip = gstr.StrTillEx(ip, ", ")
|
||||
}
|
||||
|
||||
return ip
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ func ParseSimpleRegion(ctx context.Context, id int64, spilt ...string) (string,
|
||||
}
|
||||
return ParseRegion(ctx, ids[0], ids[1], id, spilt...)
|
||||
}
|
||||
|
||||
return "", gerror.New("currently, it is only supported to regional areas")
|
||||
}
|
||||
|
||||
@@ -104,6 +103,5 @@ func ParseRegion(ctx context.Context, province int64, city int64, county int64,
|
||||
if province > 0 && city > 0 {
|
||||
return provinceName.String() + sp + cityName.String(), nil
|
||||
}
|
||||
|
||||
return provinceName.String(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user