Debian Codegraph @

src/cmd/vet/testdata/httpresponse/httpresponse.go

raw
1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package httpresponse
6
7 import (
8 "log"
9 "net/http"
10 )
11
12 func goodHTTPGet() {
13 res, err := http.Get("http://foo.com")
14 if err != nil {
15 log.Fatal(err)
16 }
17 defer res.Body.Close()
18 }
19
20 func badHTTPGet() {
21 res, err := http.Get("http://foo.com")
22 defer res.Body.Close() // ERROR "using res before checking for errors"
23 if err != nil {
24 log.Fatal(err)
25 }
26 }