Created
August 22, 2015 20:48
-
-
Save pressure679/c7b432a06168a2a982a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Problem is described at http://golang.org/pkg/net/http/#Response | |
as following: | |
// Body represents the response body. | |
// | |
// The http Client and Transport guarantee that Body is always | |
// non-nil, even on responses without a body or responses with | |
// a zero-length body. It is the caller's responsibility to | |
// close Body. The default HTTP client's Transport does not | |
// attempt to reuse HTTP/1.0 or HTTP/1.1 TCP connections | |
// ("keep-alive") unless the Body is read to completion and is | |
// closed. | |
I guess it is cause Go is only partially OOP, and that I declare | |
type response in a if-statement and return it outside the if-statement. | |
I lack the train of tohught to find a simple solution | |
*/ | |
func htmlget(website string, n int) ([]byte, error) { | |
type response http.Response // type does not have Response.Body | |
if n == 0 { | |
response, err := http.Get(website) | |
if err != nil { | |
return nil, err | |
} | |
} else { | |
response, err := http.Get(website + strconv.Itoa(n)) | |
if err != nil { | |
return nil, err | |
} | |
} | |
respbody, err := ioutil.ReadAll(response.Body) | |
defer response.Body.Close() | |
logerr(err) | |
return respbody, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment