go-weather/web.go

22 lines
402 B
Go
Raw Normal View History

package main
import (
"fmt"
"io/ioutil"
"net/http"
)
2022-08-23 14:52:06 +01:00
func loadWebPage(webURL string) ([]byte, error) {
resp, err := http.Get(webURL)
//reads html as a slice of bytes
html, err := ioutil.ReadAll(resp.Body)
2022-09-03 13:46:41 +01:00
defer resp.Body.Close()
//check response codes
if resp.StatusCode >= 400 && resp.StatusCode <= 499 {
2022-09-03 13:46:41 +01:00
err = fmt.Errorf("got response code %v", resp.StatusCode)
}
return html, err
}