github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/vet/testdata/httpresponse/httpresponse.go (about)

     1  package httpresponse
     2  
     3  import (
     4  	"log"
     5  	"net/http"
     6  )
     7  
     8  func goodHTTPGet() {
     9  	res, err := http.Get("http://foo.com")
    10  	if err != nil {
    11  		log.Fatal(err)
    12  	}
    13  	defer res.Body.Close()
    14  }
    15  
    16  func badHTTPGet() {
    17  	res, err := http.Get("http://foo.com")
    18  	defer res.Body.Close() // ERROR "using res before checking for errors"
    19  	if err != nil {
    20  		log.Fatal(err)
    21  	}
    22  }