From 109a67a68876d425a0a6b839253b9253091e6ae1 Mon Sep 17 00:00:00 2001 From: Yun Date: Fri, 1 Sep 2023 21:22:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- curlx.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/curlx.go b/curlx.go index c873b72..c14cd68 100644 --- a/curlx.go +++ b/curlx.go @@ -42,10 +42,10 @@ type CurlParams struct { Headers map[string]interface{} Cookies interface{} DataType dataType // FORM,JSON,XML + timeOutSecond int } var ( - defaultTimeOut = 180 // 默认(最长超时时间) // 默认的transport transport http.Transport = http.Transport{ // Dial: func(netw, addr string) (net.Conn, error) { @@ -81,6 +81,7 @@ type curlx struct { func NewCurlx() *curlx { return &curlx{ transport: &transport, + timeOutSecond: 60 } } @@ -116,7 +117,7 @@ func (c *curlx) WithInsecureSkipVerify() { * 设置超时时间,单位秒 */ func (c *curlx) WithTimeout(timeout int) { - c.transport.ResponseHeaderTimeout = time.Second * time.Duration(timeout) + c.timeOutSecond = timeout } /** @@ -164,7 +165,7 @@ func (c *curlx) Send(ctx context.Context, p *CurlParams) (res string, httpcode i */ func (c *curlx) sendExec(ctx context.Context, p *CurlParams) (resp *http.Response, err error) { client := &http.Client{ - Timeout: time.Second * time.Duration(defaultTimeOut), // 设置该条连接的超时 + Timeout: time.Second * time.Duration(p.timeOutSecond), // 设置该条连接的超时 Transport: c.transport, // }