diff --git a/curl.go b/curl.go index 986cb27..abab50f 100644 --- a/curl.go +++ b/curl.go @@ -111,18 +111,21 @@ func curl_(IP_ADDR string) (string, error) { HTTP_RESP, err = HTTP_CLIENT.Do(HTTP_Request) if err != nil { log.Printf("发送请求时出错: %v", err) + return "", fmt.Errorf("发送请求时出错: %v", err) } defer HTTP_RESP.Body.Close() // 检查 HTTP 响应状态码 if HTTP_RESP.StatusCode != http.StatusOK { log.Printf("HTTP 请求失败,状态码: %d", HTTP_RESP.StatusCode) + return "", fmt.Errorf("HTTP 请求失败,状态码: %d", HTTP_RESP.StatusCode) } // 读取响应体 HTTP_BODY, err = io.ReadAll(HTTP_RESP.Body) if err != nil { 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) if err != nil { fmt.Println("Error parsing JSON:", err) + return "", fmt.Errorf("解析 JSON 失败: %v", err) + } + + // 确保数据有效 + if HTPP_JSON.Code != "Success" { + log.Printf("返回数据不符合预期: %s", HTPP_JSON.Code) + return "", fmt.Errorf("返回数据不符合预期: %s", HTPP_JSON.Code) } - /* - if HTPP_JSON.Code == "Success" { - fmt.Printf("%s%s\n", HTPP_JSON.Data.Continent, HTPP_JSON.Data.Country) - } else { - fmt.Printf("Error!\n") - } - */ return fmt.Sprintf("%s%s", HTPP_JSON.Data.Continent, HTPP_JSON.Data.Country), err } diff --git a/denyip b/denyip index 692e3b8..d172209 100644 Binary files a/denyip and b/denyip differ diff --git a/main.go b/main.go index ed13476..4d3cb29 100644 --- a/main.go +++ b/main.go @@ -223,7 +223,7 @@ func runMainProcess() { // 主进程逻辑 next: 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) if _err == nil { return _len