限制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"
"net/http" "net/http"
"strings" "strings"
"time"
"github.com/goccy/go-json" "github.com/goccy/go-json"
) )
@ -45,10 +46,13 @@ func (a *Ip) GetMsg() string {
// } // }
// } // }
// fmt.Println("请求体:", string(json_data)) // fmt.Println("请求体:", string(json_data))
client := &http.Client{
resp, err := http.DefaultClient.Do(req) Timeout: 5 * time.Second, // 设置超时时间为5秒
}
resp, err := client.Do(req)
if err != nil { if err != nil {
fmt.Println("err:", err) fmt.Println("err:", err)
return "连接超时!"
} else { } else {
defer resp.Body.Close() defer resp.Body.Close()
body, err := io.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)