mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-25 14:36:35 +08:00
访问日志增加区域和ISP信息
This commit is contained in:
@@ -3,6 +3,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/iplibrary"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
@@ -161,3 +162,27 @@ func (this *IPLibraryService) DeleteIPLibrary(ctx context.Context, req *pb.Delet
|
||||
}
|
||||
return rpcutils.RPCDeleteSuccess()
|
||||
}
|
||||
|
||||
// 查询某个IP信息
|
||||
func (this *IPLibraryService) LookupIPRegion(ctx context.Context, req *pb.LookupIPRegionRequest) (*pb.LookupIPRegionResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result, err := iplibrary.SharedLibrary.Lookup(req.Ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if result == nil {
|
||||
return &pb.LookupIPRegionResponse{Region: nil}, nil
|
||||
}
|
||||
return &pb.LookupIPRegionResponse{Region: &pb.IPRegion{
|
||||
Country: result.Country,
|
||||
Region: result.Region,
|
||||
Province: result.Province,
|
||||
City: result.City,
|
||||
Isp: result.ISP,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user