From 048cd4f400c28820e1e5d03313596f25a4929654 Mon Sep 17 00:00:00 2001 From: blusewang Date: Wed, 8 Dec 2021 10:09:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=AF=B9cli=E7=9A=84?= =?UTF-8?q?=E5=85=B1=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http_client.go | 6 +----- http_client_test.go | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/http_client.go b/http_client.go index 92547e1..51c2d16 100644 --- a/http_client.go +++ b/http_client.go @@ -13,7 +13,6 @@ import ( "time" ) -var _cli *http.Client var _hook func(req *http.Request, reqBody []byte, res *http.Response, startAt time.Time, stopAt time.Time, err error) type mt struct { @@ -35,10 +34,7 @@ func (m *mt) RoundTrip(req *http.Request) (res *http.Response, err error) { } func client() *http.Client { - if _cli == nil { - _cli = &http.Client{Transport: &mt{http.Transport{}}} - } - return _cli + return &http.Client{Transport: &mt{http.Transport{}}} } func RegisterHook(hook func(req *http.Request, reqBody []byte, res *http.Response, startAt time.Time, stopAt time.Time, err error)) { diff --git a/http_client_test.go b/http_client_test.go index 33c7bcd..1977275 100644 --- a/http_client_test.go +++ b/http_client_test.go @@ -14,11 +14,12 @@ import ( "log" "net/http" "testing" + "time" ) func TestMt_RoundTrip(t *testing.T) { log.SetFlags(log.Ltime | log.Lshortfile) - RegisterHook(func(req *http.Request, reqBody []byte, res *http.Response, err error) { + RegisterHook(func(req *http.Request, reqBody []byte, res *http.Response, startAt time.Time, stopAt time.Time, err error) { var data struct { Method string `json:"method"` Url string `json:"url"`