Skip to content

Commit 5d327f8

Browse files
committed
chore: satisfy lints
Signed-off-by: Dwi Siswanto <[email protected]>
1 parent 1cc0135 commit 5d327f8

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

default_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestConnectionReuse(t *testing.T) {
3030

3131
router := httprouter.New()
3232
router.GET("/", func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
33-
fmt.Fprintf(w, "this is a test")
33+
_, _ = fmt.Fprintf(w, "this is a test")
3434
})
3535
ts := httptest.NewServer(router)
3636
defer ts.Close()
@@ -55,7 +55,7 @@ func TestConnectionReuse(t *testing.T) {
5555
resp, err := client.Do(req)
5656
require.Nil(t, err)
5757
_, _ = io.Copy(io.Discard, resp.Body)
58-
resp.Body.Close()
58+
_ = resp.Body.Close()
5959
}
6060
}()
6161
}

do.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
127127
// By default, we close the response body and return an error without
128128
// returning the response
129129
if resp != nil {
130-
resp.Body.Close()
130+
_ = resp.Body.Close()
131131
}
132132
c.closeIdleConnections()
133133
return nil, fmt.Errorf("%s %s giving up after %d attempts: %w", req.Method, req.URL, retryMax+1, err)
@@ -139,7 +139,7 @@ func (c *Client) drainBody(req *Request, resp *http.Response) {
139139
if err != nil {
140140
req.Metrics.DrainErrors++
141141
}
142-
resp.Body.Close()
142+
_ = resp.Body.Close()
143143
}
144144

145145
const closeConnectionsCounter = 100
@@ -248,5 +248,5 @@ func (c *Client) wrapContextWithTrace(req *Request) {
248248
}
249249
req.TraceInfo = traceInfo
250250

251-
req.Request = req.Request.WithContext(httptrace.WithClientTrace(req.Request.Context(), trace))
251+
req.Request = req.Request.WithContext(httptrace.WithClientTrace(req.Context(), trace))
252252
}

request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (r *Request) WithContext(ctx context.Context) *Request {
9393
// This function is not thread-safe; do not call it at the same time as another
9494
// call, or at the same time this request is being used with Client.Do.
9595
func (r *Request) BodyBytes() ([]byte, error) {
96-
if r.Request.Body == nil {
96+
if r.Body == nil {
9797
return nil, nil
9898
}
9999
buf := new(bytes.Buffer)

request_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestRedirectPOSTWithBody(t *testing.T) {
9898
if err != nil {
9999
t.Fatalf("client.Do failed: %v", err)
100100
}
101-
defer resp.Body.Close()
101+
defer func() { _ = resp.Body.Close() }()
102102

103103
if resp.StatusCode != http.StatusOK {
104104
body, _ := io.ReadAll(resp.Body)
@@ -135,7 +135,7 @@ func TestRedirectPOSTWithBodyFromRequest(t *testing.T) {
135135
if err != nil {
136136
t.Fatalf("client.Do failed: %v", err)
137137
}
138-
defer resp.Body.Close()
138+
defer func() { _ = resp.Body.Close() }()
139139

140140
if resp.StatusCode != http.StatusOK {
141141
body, _ := io.ReadAll(resp.Body)
@@ -158,7 +158,7 @@ func setupRedirectServer(t *testing.T, expectedBody string) *httptest.Server {
158158
if err != nil {
159159
t.Logf("redirect read body err: %v", err)
160160
}
161-
r.Body.Close()
161+
_ = r.Body.Close()
162162

163163
w.Header().Set("Location", "/target")
164164
w.WriteHeader(http.StatusTemporaryRedirect) // 307
@@ -170,24 +170,24 @@ func setupRedirectServer(t *testing.T, expectedBody string) *httptest.Server {
170170
w.WriteHeader(http.StatusInternalServerError)
171171
return
172172
}
173-
r.Body.Close()
173+
_ = r.Body.Close()
174174

175175
if len(body) == 0 {
176176
w.WriteHeader(http.StatusBadRequest)
177-
w.Write([]byte("empty body"))
177+
_, _ = w.Write([]byte("empty body"))
178178

179179
return
180180
}
181181

182182
if string(body) != expectedBody {
183183
w.WriteHeader(http.StatusBadRequest)
184-
w.Write([]byte("body mismatch"))
184+
_, _ = w.Write([]byte("body mismatch"))
185185

186186
return
187187
}
188188

189189
w.WriteHeader(http.StatusOK)
190-
w.Write([]byte("success"))
190+
_, _ = w.Write([]byte("success"))
191191
})
192192

193193
return httptest.NewServer(mux)

util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Discard(req *Request, resp *http.Response, RespReadLimit int64) {
1919
if err != nil {
2020
req.Metrics.DrainErrors++
2121
}
22-
resp.Body.Close()
22+
_ = resp.Body.Close()
2323
}
2424

2525
// getLength returns length of a Reader efficiently

0 commit comments

Comments
 (0)