From 144b147606c56485bf6e1d32b782b26d394e9d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E5=90=83=E7=82=B9=E8=8B=B9=E6=9E=9C?= <73388495+eatmoreapple@users.noreply.github.com> Date: Sun, 11 Dec 2022 12:26:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0client=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E9=87=8D=E8=AF=95=E6=AC=A1=E6=95=B0=20(#151)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client.go b/client.go index e1bdc2a..957ae8a 100644 --- a/client.go +++ b/client.go @@ -40,10 +40,11 @@ func (u UserAgentHook) AfterRequest(response *http.Response, err error) {} type Client struct { HttpHooks HttpHooks *http.Client - Domain WechatDomain - mode Mode - mu sync.Mutex - cookies map[string][]*http.Cookie + Domain WechatDomain + mode Mode + mu sync.Mutex + MaxRetryTimes int + cookies map[string][]*http.Cookie } func NewClient() *Client { @@ -64,6 +65,7 @@ func NewClient() *Client { func DefaultClient() *Client { client := NewClient() client.AddHttpHook(UserAgentHook{}) + client.MaxRetryTimes = 5 return client } @@ -71,8 +73,6 @@ func (c *Client) AddHttpHook(hooks ...HttpHook) { c.HttpHooks = append(c.HttpHooks, hooks...) } -const maxRetry = 2 - func (c *Client) do(req *http.Request) (*http.Response, error) { for _, hook := range c.HttpHooks { hook.BeforeRequest(req) @@ -81,7 +81,7 @@ func (c *Client) do(req *http.Request) (*http.Response, error) { resp *http.Response err error ) - for i := 0; i < maxRetry; i++ { + for i := 0; i < c.MaxRetryTimes; i++ { resp, err = c.Client.Do(req) if err == nil { break