go-weather/web.go
2022-09-03 13:46:41 +01:00

22 lines
402 B
Go

package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func loadWebPage(webURL string) ([]byte, error) {
resp, err := http.Get(webURL)
//reads html as a slice of bytes
html, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
//check response codes
if resp.StatusCode >= 400 && resp.StatusCode <= 499 {
err = fmt.Errorf("got response code %v", resp.StatusCode)
}
return html, err
}