diff options
author | Keuin <[email protected]> | 2023-07-14 22:25:27 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-07-14 22:25:27 +0800 |
commit | 2ace07d2d88c01a56b4d0f3194bd74a518a769c8 (patch) | |
tree | b218043dacec97c08469855950838ceca67496c6 /bilibili/request.go | |
parent | d7bd3edf61109936a09a5115938e86b1c17ea024 (diff) |
Refactor: use pointer type of `Bilibili` to prevent unexpected copy.
Diffstat (limited to 'bilibili/request.go')
-rw-r--r-- | bilibili/request.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/bilibili/request.go b/bilibili/request.go index fa31b19..11ff995 100644 --- a/bilibili/request.go +++ b/bilibili/request.go @@ -10,7 +10,7 @@ import ( ) // newRequest create an HTTP request with per-instance User-Agent set. -func (b Bilibili) newRequest( +func (b *Bilibili) newRequest( method string, url string, body io.Reader, @@ -25,12 +25,12 @@ func (b Bilibili) newRequest( } // newRequest create an HTTP GET request with an empty body and per-instance User-Agent set. -func (b Bilibili) newGet(url string) (req *http.Request, err error) { +func (b *Bilibili) newGet(url string) (req *http.Request, err error) { return b.newRequest("GET", url, strings.NewReader("")) } // callGet make a GET request and parse response as a JSON document with given model. -func callGet[T types.BaseResponse[V], V any](b Bilibili, url string) (resp T, err error) { +func callGet[T types.BaseResponse[V], V any](b *Bilibili, url string) (resp T, err error) { req, err := b.newGet(url) if err != nil { b.logger.Error("Cannot create HTTP request instance on API %v: %v", url, err) @@ -67,7 +67,7 @@ func callGet[T types.BaseResponse[V], V any](b Bilibili, url string) (resp T, er return } -func (b Bilibili) Do(req *http.Request) (resp *http.Response, err error) { +func (b *Bilibili) Do(req *http.Request) (resp *http.Response, err error) { transport := http.DefaultTransport.(*http.Transport).Clone() transport.DialTLSContext = nil |