This commit is contained in:
akiba
2023-09-14 20:44:46 +08:00
parent 258bd0c72f
commit 6833089dc9
2 changed files with 25 additions and 115 deletions

View File

@@ -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 {