api-server/api/network/server/ip_api.go
2024-09-25 16:35:07 +08:00

48 lines
934 B
Go

package server
import (
"api/api/network/model"
"api/api/network/model/req"
"api/utils"
"api/utils/r"
"bufio"
"fmt"
"github.com/gin-gonic/gin"
)
// IpApi ip接口
type IpApi struct {
}
// GetIpInfo 获取IP信息
func (*IpApi) GetIpInfo(c *gin.Context) {
data := utils.BindValidJson[req.GetIpInfoRequest](c)
ipInfo, err := ipService.GetIpInfo(data.IP)
if err != nil {
r.Error(c)
}
r.SuccessData(c, ipInfo)
return
}
// GetIpInfoList 获取IP信息
func (*IpApi) GetIpInfoList(c *gin.Context) {
scanner := bufio.NewScanner(c.Request.Body)
var ipInfoList []model.IpInfo
for scanner.Scan() {
line := scanner.Text()
ipInfo, err := ipService.GetIpInfo(line)
if err != nil {
continue
}
if ipInfo.ISP == "谷歌" {
ipInfoList = append(ipInfoList, ipInfo)
fmt.Println(ipInfo.IP)
}
// 在这里你可以处理每一行的数据,执行你的业务逻辑
}
r.SuccessData(c, ipInfoList)
return
}