httpresponse

Imports

Imports #

"go/ast"
"go/types"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
"golang.org/x/tools/go/ast/inspector"
"golang.org/x/tools/internal/typesinternal"

Constants & Variables

Analyzer var #

var Analyzer = *ast.UnaryExpr

Doc const #

const Doc = `check for mistakes using HTTP responses

A common mistake when using the net/http package is to defer a function
call to close the http.Response Body before checking the error that
determines whether the response is valid:

	resp, err := http.Head(url)
	defer resp.Body.Close()
	if err != nil {
		log.Fatal(err)
	}
	// (defer statement belongs here)

This checker helps uncover latent nil dereference bugs by reporting a
diagnostic for such mistakes.`

Functions

isHTTPFuncOrMethodOnClient function #

isHTTPFuncOrMethodOnClient checks whether the given call expression is on either a function of the net/http package or a method of http.Client that returns (*http.Response, error).

func isHTTPFuncOrMethodOnClient(info *types.Info, expr *ast.CallExpr) bool

restOfBlock function #

restOfBlock, given a traversal stack, finds the innermost containing block and returns the suffix of its statements starting with the current node, along with the number of call expressions encountered.

func restOfBlock(stack []ast.Node) ([]ast.Stmt, int)

rootIdent function #

rootIdent finds the root identifier x in a chain of selections x.y.z, or nil if not found.

func rootIdent(n ast.Node) *ast.Ident

run function #

func run(pass *analysis.Pass) (interface{}, error)

Generated with Arrow