diff --git a/workers/ip.go b/workers/ip.go index 1519719..4fd031b 100644 --- a/workers/ip.go +++ b/workers/ip.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "strings" + "time" "github.com/goccy/go-json" ) @@ -45,10 +46,13 @@ func (a *Ip) GetMsg() string { // } // } // fmt.Println("请求体:", string(json_data)) - - resp, err := http.DefaultClient.Do(req) + client := &http.Client{ + Timeout: 5 * time.Second, // 设置超时时间为5秒 + } + resp, err := client.Do(req) if err != nil { fmt.Println("err:", err) + return "连接超时!" } else { defer resp.Body.Close() body, err := io.ReadAll(resp.Body)