summaryrefslogtreecommitdiff
path: root/bilibili/request.go
diff options
context:
space:
mode:
Diffstat (limited to 'bilibili/request.go')
-rw-r--r--bilibili/request.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/bilibili/request.go b/bilibili/request.go
index 11ff995..613530c 100644
--- a/bilibili/request.go
+++ b/bilibili/request.go
@@ -29,8 +29,8 @@ 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) {
+// callGetRaw make a GET request and returns the raw response body.
+func callGetRaw(b *Bilibili, url string) (resp *http.Response, respBody []byte, err error) {
req, err := b.newGet(url)
if err != nil {
b.logger.Error("Cannot create HTTP request instance on API %v: %v", url, err)
@@ -56,6 +56,16 @@ func callGet[T types.BaseResponse[V], V any](b *Bilibili, url string) (resp T, e
return
}
+ return r, data, err
+}
+
+// callGet make a GET request and parse response as a JSON document with given model.
+func callGet[T BaseResponse[V], V any](b Bilibili, url string) (resp T, err error) {
+ r, data, err := callGetRaw(b, url)
+ if err != nil {
+ return
+ }
+
err = json.Unmarshal(data, &resp)
if err != nil {
b.logger.Error("Invalid JSON body of HTTP response on API %v: %v. Text: \"%v\"",