Skip to content

Files

Latest commit

 

History

History
37 lines (27 loc) · 670 Bytes

httpresponse.md

File metadata and controls

37 lines (27 loc) · 670 Bytes

Pattern: Misuse of HTTP response

Issue: -

Description

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()
}

Further Reading