added resp error handling and seperate func
This commit is contained in:
parent
30e6bcac6a
commit
0f32422d87
27
web.go
Normal file
27
web.go
Normal file
@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func loadWebPage(web_url string) ([]byte, error) {
|
||||
resp, err := http.Get(web_url)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
//reads html as a slice of bytes
|
||||
html, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
|
||||
//check response codes
|
||||
if resp.StatusCode >= 400 && resp.StatusCode <= 499 {
|
||||
err = fmt.Errorf("response Code: %v", resp.StatusCode)
|
||||
}
|
||||
return html, err
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user