mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2025-12-08 20:28:13 +08:00
🎨 api: GetJson && 更改错误处理逻辑
This commit is contained in:
18
api/utils.go
Normal file
18
api/utils.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetJson(url string, result interface{}) error {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if err = json.NewDecoder(resp.Body).Decode(result); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user