Skip to content

Commit 4d35a4c

Browse files
committed
Lint: fix errcheck for browse, fastcgi_test, fcgiclient, fcgiclient_test caddyserver#2541
1 parent 30f1250 commit 4d35a4c

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

caddyhttp/browse/browse.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -59,34 +59,34 @@ type Config struct {
5959

6060
// A Listing is the context used to fill out a template.
6161
type Listing struct {
62-
// The name of the directory (the last element of the path)
62+
// The name of the directory (the last element of the path).
6363
Name string
6464

65-
// The full path of the request
65+
// The full path of the request.
6666
Path string
6767

68-
// Whether the parent directory is browsable
68+
// Whether the parent directory is browse-able.
6969
CanGoUp bool
7070

71-
// The items (files and folders) in the path
71+
// The items (files and folders) in the path.
7272
Items []FileInfo
7373

74-
// The number of directories in the listing
74+
// The number of directories in the listing.
7575
NumDirs int
7676

77-
// The number of files (items that aren't directories) in the listing
77+
// The number of files (items that aren't directories) in the listing.
7878
NumFiles int
7979

80-
// Which sorting order is used
80+
// Which sorting order is used.
8181
Sort string
8282

83-
// And which order
83+
// And which order.
8484
Order string
8585

86-
// If ≠0 then Items have been limited to that many elements
86+
// If ≠0 then Items have been limited to that many elements.
8787
ItemsLimitedTo int
8888

89-
// Optional custom variables for use in browse templates
89+
// Optional custom variables for use in browse templates.
9090
User interface{}
9191

9292
httpserver.Context
@@ -272,14 +272,14 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config
272272
continue
273273
}
274274

275-
URL := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name
275+
_url := url.URL{Path: "./" + name} // prepend with "./" to fix paths with ':' in the name
276276

277277
fileInfos = append(fileInfos, FileInfo{
278278
IsDir: isDir,
279279
IsSymlink: isSymlink(f),
280280
Name: f.Name(),
281281
Size: f.Size(),
282-
URL: URL.String(),
282+
URL: _url.String(),
283283
ModTime: f.ModTime().UTC(),
284284
Mode: f.Mode(),
285285
})

caddyhttp/fastcgi/fastcgi_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func TestServeHTTP(t *testing.T) {
4141
t.Fatalf("Unable to create listener for test: %v", err)
4242
}
4343
defer listener.Close()
44+
4445
go func() {
4546
err := fcgi.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
4647
w.Header().Set("Content-Length", bodyLenStr)
@@ -366,9 +367,14 @@ func TestSendTimeout(t *testing.T) {
366367
}
367368
w := httptest.NewRecorder()
368369

369-
go fcgi.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
370-
w.WriteHeader(http.StatusOK)
371-
}))
370+
go func() {
371+
err := fcgi.Serve(listener, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
372+
w.WriteHeader(http.StatusOK)
373+
}))
374+
if err != nil {
375+
log.Printf("[ERROR] unable to start server: %v", err)
376+
}
377+
}()
372378

373379
got, err := handler.ServeHTTP(w, r)
374380
if test.shouldErr {

caddyhttp/fastcgi/fcgiclient.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func (c *FCGIClient) Do(p map[string]string, req io.Reader) (r io.Reader, err er
395395

396396
body := newWriter(c, Stdin)
397397
if req != nil {
398-
io.Copy(body, req)
398+
_, _ = io.Copy(body, req)
399399
}
400400
body.Close()
401401

caddyhttp/fastcgi/fcgiclient_test.go

+22-13
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ type FastCGIServer struct{}
5959

6060
func (s FastCGIServer) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
6161

62-
req.ParseMultipartForm(100000000)
62+
if err := req.ParseMultipartForm(100000000); err != nil {
63+
log.Printf("[ERROR] failed to parse: %v", err)
64+
}
6365

6466
stat := "PASSED"
6567
fmt.Fprintln(resp, "-")
@@ -68,15 +70,15 @@ func (s FastCGIServer) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
6870
length := 0
6971
for k0, v0 := range req.Form {
7072
h := md5.New()
71-
io.WriteString(h, v0[0])
72-
md5 := fmt.Sprintf("%x", h.Sum(nil))
73+
_, _ = io.WriteString(h, v0[0])
74+
_md5 := fmt.Sprintf("%x", h.Sum(nil))
7375

7476
length += len(k0)
7577
length += len(v0[0])
7678

77-
// echo error when key != md5(val)
78-
if md5 != k0 {
79-
fmt.Fprintln(resp, "server:err ", md5, k0)
79+
// echo error when key != _md5(val)
80+
if _md5 != k0 {
81+
fmt.Fprintln(resp, "server:err ", _md5, k0)
8082
stat = "FAILED"
8183
}
8284
}
@@ -197,7 +199,9 @@ func generateRandFile(size int) (p string, m string) {
197199
for i := 0; i < size/16; i++ {
198200
buf := make([]byte, 16)
199201
binary.PutVarint(buf, rand.Int63())
200-
fo.Write(buf)
202+
if _, err := fo.Write(buf); err != nil {
203+
log.Printf("[ERROR] failed to write buffer: %v\n", err)
204+
}
201205
h.Write(buf)
202206
}
203207
m = fmt.Sprintf("%x", h.Sum(nil))
@@ -214,12 +218,13 @@ func DisabledTest(t *testing.T) {
214218
go func() {
215219
listener, err := net.Listen("tcp", ipPort)
216220
if err != nil {
217-
// handle error
218221
log.Println("listener creation failed: ", err)
219222
}
220223

221224
srv := new(FastCGIServer)
222-
fcgi.Serve(listener, srv)
225+
if err := fcgi.Serve(listener, srv); err != nil {
226+
log.Print("[ERROR] failed to start server: ", err)
227+
}
223228
}()
224229

225230
time.Sleep(1 * time.Second)
@@ -244,7 +249,7 @@ func DisabledTest(t *testing.T) {
244249
for i := 0x00; i < 0xff; i++ {
245250
v0 := strings.Repeat(string(i), 256)
246251
h := md5.New()
247-
io.WriteString(h, v0)
252+
_, _ = io.WriteString(h, v0)
248253
k0 := fmt.Sprintf("%x", h.Sum(nil))
249254
data += k0 + "=" + url.QueryEscape(v0) + "&"
250255
}
@@ -261,7 +266,7 @@ func DisabledTest(t *testing.T) {
261266
for i := 0x00; i < 0xff; i++ {
262267
v0 := strings.Repeat(string(i), 4096)
263268
h := md5.New()
264-
io.WriteString(h, v0)
269+
_, _ = io.WriteString(h, v0)
265270
k0 := fmt.Sprintf("%x", h.Sum(nil))
266271
p1[k0] = v0
267272
}
@@ -285,6 +290,10 @@ func DisabledTest(t *testing.T) {
285290
delete(f0, "m0")
286291
sendFcgi(1, fcgiParams, nil, nil, f0)
287292

288-
os.Remove(path0)
289-
os.Remove(path1)
293+
if err := os.Remove(path0); err != nil {
294+
log.Println("failed to remove path: ", err)
295+
}
296+
if err := os.Remove(path1); err != nil {
297+
log.Println("failed to remove path: ", err)
298+
}
290299
}

0 commit comments

Comments
 (0)