限制ip查询时间

This commit is contained in:
liyp 2024-04-18 19:36:32 +08:00
parent 5def1cd668
commit cc2d768474

View file

@ -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)