Skip to content

Commit

Permalink
移除对cli的共享
Browse files Browse the repository at this point in the history
  • Loading branch information
blusewang committed Dec 8, 2021
1 parent 78d3fc4 commit 048cd4f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 1 addition & 5 deletions http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)) {
Expand Down
3 changes: 2 additions & 1 deletion http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 048cd4f

Please sign in to comment.