本篇文章說明 Http Request 的部分,並將資料讀取成 byte[],後續要轉成 string 或 JSON 都比較方便,使用兩個 package 的部分函式,io/ioutilnet/http

Http.Get

1
2
3
4
5
resp, err := http.Get("http://example.com/")
if err != nil {
// handle error
}
defer resp.Body.Close()

io.ReadAll

1
body, err := io.ReadAll(resp.Body)