Skip to content

Commit cb74dda

Browse files
committed
Lint: fix errcheck for policy, body_test, proxy_test caddyserver#2541
1 parent 281c272 commit cb74dda

File tree

3 files changed

+142
-59
lines changed

3 files changed

+142
-59
lines changed

caddyhttp/proxy/body_test.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"bytes"
1919
"io"
2020
"io/ioutil"
21+
"log"
2122
"net/http"
2223
"net/http/httptest"
2324
"testing"
@@ -47,12 +48,16 @@ func TestBodyRetry(t *testing.T) {
4748
// simulate fail request
4849
host := req.URL.Host
4950
req.URL.Host = "example.com"
50-
body.rewind()
51+
if err := body.rewind(); err != nil {
52+
log.Println("[ERROR] failed re-read bufferedBody: ", err)
53+
}
5154
_, _ = http.DefaultTransport.RoundTrip(req)
5255

5356
// retry request
5457
req.URL.Host = host
55-
body.rewind()
58+
if err := body.rewind(); err != nil {
59+
log.Println("[ERROR] failed re-read bufferedBody: ", err)
60+
}
5661
resp, err := http.DefaultTransport.RoundTrip(req)
5762
if err != nil {
5863
t.Fatal(err)
@@ -67,7 +72,9 @@ func TestBodyRetry(t *testing.T) {
6772
}
6873

6974
// try one more time for body reuse
70-
body.rewind()
75+
if err := body.rewind(); err != nil {
76+
log.Println("[ERROR] failed re-read bufferedBody: ", err)
77+
}
7178
resp, err = http.DefaultTransport.RoundTrip(req)
7279
if err != nil {
7380
t.Fatal(err)

caddyhttp/proxy/policy.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package proxy
1616

1717
import (
1818
"hash/fnv"
19+
"log"
1920
"math"
2021
"math/rand"
2122
"net"
@@ -139,7 +140,9 @@ func hostByHashing(pool HostPool, s string) *UpstreamHost {
139140
// hash calculates a hash based on string s
140141
func hash(s string) uint32 {
141142
h := fnv.New32a()
142-
h.Write([]byte(s))
143+
if _, err := h.Write([]byte(s)); err != nil {
144+
log.Println("[ERROR] failed to write bytes: ", err)
145+
}
143146
return h.Sum32()
144147
}
145148

0 commit comments

Comments
 (0)