From b6eb2c0da4e653c6fdd278bcbdcd55ec376cd481 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sun, 2 Jul 2023 14:48:47 +0800 Subject: Refactor: move RoomId type to the correct package. Type all room ID usages. --- common/testing/testutil.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++ common/testutil.go | 46 --------------------------------------------- common/types.go | 3 --- 3 files changed, 47 insertions(+), 49 deletions(-) create mode 100644 common/testing/testutil.go delete mode 100644 common/testutil.go delete mode 100644 common/types.go (limited to 'common') diff --git a/common/testing/testutil.go b/common/testing/testutil.go new file mode 100644 index 0000000..509c619 --- /dev/null +++ b/common/testing/testutil.go @@ -0,0 +1,47 @@ +package testing + +import ( + "encoding/json" + "fmt" + "github.com/keuin/slbr/bilibili" + "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 bilibili.RoomId `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 +} diff --git a/common/testutil.go b/common/testutil.go deleted file mode 100644 index d6c3899..0000000 --- a/common/testutil.go +++ /dev/null @@ -1,46 +0,0 @@ -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 -} diff --git a/common/types.go b/common/types.go deleted file mode 100644 index 81456b4..0000000 --- a/common/types.go +++ /dev/null @@ -1,3 +0,0 @@ -package common - -type RoomId uint64 -- cgit v1.2.3