使用查询本地IP库代替API查询IP信息

This commit is contained in:
刘祥超
2023-08-24 12:22:16 +08:00
parent 15f2a2d517
commit 3f664882d5
12 changed files with 45 additions and 168 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/users/userutils"
"github.com/TeaOSLab/EdgeCommon/pkg/iplibrary"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
@@ -60,13 +61,9 @@ func (this *UserAction) RunGet(params struct {
// IP地址
var registeredRegion = ""
if len(user.RegisteredIP) > 0 {
regionResp, err := this.RPC().IPLibraryRPC().LookupIPRegion(this.AdminContext(), &pb.LookupIPRegionRequest{Ip: user.RegisteredIP})
if err != nil {
this.ErrorPage(err)
return
}
if regionResp.IpRegion != nil {
registeredRegion = regionResp.IpRegion.Summary
var ipRegion = iplibrary.LookupIP(user.RegisteredIP)
if ipRegion != nil && ipRegion.IsOk() {
registeredRegion = ipRegion.Summary()
}
}