summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-09-16 21:14:50 +0800
committerKeuin <[email protected]>2022-09-16 21:14:50 +0800
commite36b9574037d3ddea06a65351b57840fe05bc4a8 (patch)
treef4ec8422a393d17bbf75b004362914f68a9c90d2 /common
parent7d8ec5f208c645fef71e2b1fd9ce1f891edfda45 (diff)
Add test for core bilibili API wrappers.
Diffstat (limited to 'common')
-rw-r--r--common/testutil.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/common/testutil.go b/common/testutil.go
new file mode 100644
index 0000000..d6c3899
--- /dev/null
+++ b/common/testutil.go
@@ -0,0 +1,46 @@
+package common
+
+import (
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+)
+
+/*
+Some utility function for test-purpose only.
+*/
+
+type LiveList struct {
+ Code int `json:"code"`
+ Message string `json:"message"`
+ TTL int `json:"ttl"`
+ Data struct {
+ Count int `json:"count"`
+ Data []struct {
+ Face string `json:"face"`
+ Link string `json:"link"`
+ Roomid int `json:"roomid"`
+ Roomname string `json:"roomname"`
+ Nickname string `json:"nickname"`
+ } `json:"data"`
+ } `json:"data"`
+}
+
+func GetLiveListForGuestUser() (liveList LiveList, err error) {
+ url := "https://api.live.bilibili.com/xlive/web-interface/v1/index/WebGetUnLoginRecList"
+ resp, err := http.Get(url)
+ if err != nil {
+ return
+ }
+ if resp.StatusCode != http.StatusOK {
+ err = fmt.Errorf("bad http response: %v", resp.StatusCode)
+ return
+ }
+ b, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return
+ }
+ err = json.Unmarshal(b, &liveList)
+ return
+}