1package a
2
3import (
4	"fmt"
5	"net/http"
6)
7
8func f1() {
9	resp, err := http.Get("http://example.com/") // OK
10	if err != nil {
11		// handle error
12	}
13	resp.Body.Close()
14
15	resp2, err := http.Get("http://example.com/") // OK
16	if err != nil {
17		// handle error
18	}
19	resp2.Body.Close()
20}
21
22func f2() {
23	resp, err := http.Get("http://example.com/") // OK
24	if err != nil {
25		// handle error
26	}
27	body := resp.Body
28	body.Close()
29
30	resp2, err := http.Get("http://example.com/") // OK
31	body2 := resp2.Body
32	body2.Close()
33	if err != nil {
34		// handle error
35	}
36}
37
38func f3() {
39	resp, err := http.Get("http://example.com/") // OK
40	if err != nil {
41		// handle error
42	}
43	defer resp.Body.Close()
44}
45
46func f4() {
47	resp, err := http.Get("http://example.com/") // want "response body must be closed"
48	if err != nil {
49		// handle error
50	}
51	fmt.Print(resp)
52
53	resp, err = http.Get("http://example.com/") // want "response body must be closed"
54	if err != nil {
55		// handle error
56	}
57	fmt.Print(resp.Status)
58
59	resp, err = http.Get("http://example.com/") // want "response body must be closed"
60	if err != nil {
61		// handle error
62	}
63	fmt.Print(resp.Body)
64	return
65}
66
67func f5() {
68	_, err := http.Get("http://example.com/") // want "response body must be closed"
69	if err != nil {
70		// handle error
71	}
72}
73
74func f6() {
75	http.Get("http://example.com/") // want "response body must be closed"
76}
77
78func f7() {
79	res, _ := http.Get("http://example.com/") // OK
80	resCloser := func() {
81		res.Body.Close()
82	}
83	resCloser()
84}
85
86func f8() {
87	res, _ := http.Get("http://example.com/") // want "response body must be closed"
88	_ = func() {
89		res.Body.Close()
90	}
91}
92
93func f9() {
94	_ = func() {
95		res, _ := http.Get("http://example.com/") // OK
96		res.Body.Close()
97	}
98}
99
100func f10() {
101	res, _ := http.Get("http://example.com/") // OK
102	resCloser := func(res *http.Response) {
103		res.Body.Close()
104	}
105	resCloser(res)
106}
107
108func handleResponse(res *http.Response) {
109	res.Body.Close()
110}
111
112func f11() {
113	res, _ := http.Get("http://example.com/") // OK
114	handleResponse(res)
115}
116