mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2025-12-10 21:28:14 +08:00
update
This commit is contained in:
19
api/utils.go
19
api/utils.go
@@ -2,9 +2,28 @@ package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func HttpGet(url string, headers *http.Header) ([]byte, error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
req.Header = *headers
|
||||
c := &http.Client{}
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func GetJson(url string, result interface{}) error {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user