From 3e167178df3fed5edfe3ace8c0c6103bbcf08240 Mon Sep 17 00:00:00 2001 From: eatmoreapple <15055461510@163.com> Date: Fri, 17 Dec 2021 10:09:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmessage=E6=97=A0=E6=B3=95json?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 28 ++++++++++++++-------------- message.go | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/client.go b/client.go index df48da7..8a45d6f 100644 --- a/client.go +++ b/client.go @@ -46,25 +46,25 @@ type Client struct { cookies map[string][]*http.Cookie } -func NewClient(client *http.Client) *Client { - return &Client{Client: client} +func NewClient() *Client { + jar, _ := cookiejar.New(nil) + timeout := 30 * time.Second + return &Client{ + Client: &http.Client{ + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + Jar: jar, + Timeout: timeout, + }} } // DefaultClient 自动存储cookie // 设置客户端不自动跳转 func DefaultClient() *Client { - jar, _ := cookiejar.New(nil) - timeout := 30 * time.Second - client := &http.Client{ - CheckRedirect: func(req *http.Request, via []*http.Request) error { - return http.ErrUseLastResponse - }, - Jar: jar, - Timeout: timeout, - } - c := NewClient(client) - c.AddHttpHook(UserAgentHook{}) - return c + client := NewClient() + client.AddHttpHook(UserAgentHook{}) + return client } func (c *Client) AddHttpHook(hooks ...HttpHook) { diff --git a/message.go b/message.go index 06c7d3f..ea2d86e 100644 --- a/message.go +++ b/message.go @@ -48,9 +48,9 @@ type Message struct { Url string senderInGroupUserName string RecommendInfo RecommendInfo - Bot *Bot + Bot *Bot `json:"-"` mu sync.RWMutex - Context context.Context + Context context.Context `json:"-"` item map[string]interface{} }