Pattern: Misuse of HTTP response
Issue: -
This rule ensures that errors are checked before using HTTP Response.
Example of incorrect code:
func badHTTPGet() {
res, err := http.Get("http://foo.com")
defer res.Body.Close() // using res before checking for errors
if err != nil {
log.Fatal(err)
}
}
Example of correct code:
func goodHTTPGet() {
res, err := http.Get("http://foo.com")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
}