🎨 api: GetJson && 更改错误处理逻辑

This commit is contained in:
Akiba
2022-05-14 15:16:16 +08:00
parent 1081db0728
commit 885e694223
2 changed files with 22 additions and 17 deletions

18
api/utils.go Normal file
View 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
}