You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-weather/web.go

21 lines
402 B

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
}