修护curl潜在bug

This commit is contained in:
aixiao 2025-01-17 09:39:22 +08:00
parent cd01d1758a
commit 4fd5dbe873
3 changed files with 11 additions and 8 deletions

15
curl.go
View File

@ -111,18 +111,21 @@ func curl_(IP_ADDR string) (string, error) {
HTTP_RESP, err = HTTP_CLIENT.Do(HTTP_Request) HTTP_RESP, err = HTTP_CLIENT.Do(HTTP_Request)
if err != nil { if err != nil {
log.Printf("发送请求时出错: %v", err) log.Printf("发送请求时出错: %v", err)
return "", fmt.Errorf("发送请求时出错: %v", err)
} }
defer HTTP_RESP.Body.Close() defer HTTP_RESP.Body.Close()
// 检查 HTTP 响应状态码 // 检查 HTTP 响应状态码
if HTTP_RESP.StatusCode != http.StatusOK { if HTTP_RESP.StatusCode != http.StatusOK {
log.Printf("HTTP 请求失败,状态码: %d", HTTP_RESP.StatusCode) log.Printf("HTTP 请求失败,状态码: %d", HTTP_RESP.StatusCode)
return "", fmt.Errorf("HTTP 请求失败,状态码: %d", HTTP_RESP.StatusCode)
} }
// 读取响应体 // 读取响应体
HTTP_BODY, err = io.ReadAll(HTTP_RESP.Body) HTTP_BODY, err = io.ReadAll(HTTP_RESP.Body)
if err != nil { if err != nil {
log.Printf("读取响应体时出错: %v", err) log.Printf("读取响应体时出错: %v", err)
return "", fmt.Errorf("读取响应体时出错: %v", err)
} }
// 保存响应体到文件 // 保存响应体到文件
@ -134,14 +137,14 @@ func curl_(IP_ADDR string) (string, error) {
err = json.Unmarshal(HTTP_BODY, &HTPP_JSON) err = json.Unmarshal(HTTP_BODY, &HTPP_JSON)
if err != nil { if err != nil {
fmt.Println("Error parsing JSON:", err) fmt.Println("Error parsing JSON:", err)
return "", fmt.Errorf("解析 JSON 失败: %v", err)
} }
/*
if HTPP_JSON.Code == "Success" { // 确保数据有效
fmt.Printf("%s%s\n", HTPP_JSON.Data.Continent, HTPP_JSON.Data.Country) if HTPP_JSON.Code != "Success" {
} else { log.Printf("返回数据不符合预期: %s", HTPP_JSON.Code)
fmt.Printf("Error!\n") return "", fmt.Errorf("返回数据不符合预期: %s", HTPP_JSON.Code)
} }
*/
return fmt.Sprintf("%s%s", HTPP_JSON.Data.Continent, HTPP_JSON.Data.Country), err return fmt.Sprintf("%s%s", HTPP_JSON.Data.Continent, HTPP_JSON.Data.Country), err
} }

BIN
denyip

Binary file not shown.

View File

@ -223,7 +223,7 @@ func runMainProcess() { // 主进程逻辑
next: next:
IpMutex.Unlock() // 解锁互斥锁 IpMutex.Unlock() // 解锁互斥锁
log.Printf(" 当前Ip链表长度:%d, Ipset名:%s, 长:%d ProcessedIPMap当前长度:%d\n", IpList.Len(), IPSET_NAME, func() int { // 打印 当前 Ipset 链长度 log.Printf(" 当前Ip链表长度:%d, Ipset名:%s, 长:%d, ProcessedIPMap当前长度:%d\n", IpList.Len(), IPSET_NAME, func() int { // 打印 当前 Ipset 链长度
_len, _err := NumIPSet(IPSET_NAME) _len, _err := NumIPSet(IPSET_NAME)
if _err == nil { if _err == nil {
return _len return _len