Skip to content

Commit 1b2f5b3

Browse files
committed
fix: lint
1 parent 926dd1f commit 1b2f5b3

File tree

5 files changed

+49
-19
lines changed

5 files changed

+49
-19
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"gopls": {
2424
"formatting.gofumpt": true,
2525
"formatting.local": "fastcat.org"
26-
}
26+
},
27+
"go.lintTool": "golangci-lint-v2"
2728
}

addons/gocache/http/backend.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (b *backend) Open(name string) (fs.File, error) {
8989
}
9090
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
9191
_, _ = io.Copy(io.Discard, resp.Body)
92-
resp.Body.Close()
92+
_ = resp.Body.Close()
9393
if err := statusError(resp.StatusCode); err != nil {
9494
return nil, fmt.Errorf("failed to open %q: %s: %w", u, resp.Status, err)
9595
}
@@ -144,20 +144,19 @@ func (b *backend) Remove(name string) error {
144144
if err != nil {
145145
return fmt.Errorf("failed to remove %q: %w", u, err)
146146
}
147+
_, _ = io.Copy(io.Discard, resp.Body)
148+
_ = resp.Body.Close()
147149
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
148-
resp.Body.Close()
149150
return fmt.Errorf("failed to remove %q: %s", u, resp.Status)
150151
}
151-
_, _ = io.Copy(io.Discard, resp.Body)
152-
resp.Body.Close()
153152
return nil
154153
}
155154

156155
// Rename implements gocache.DiskDirFS.
157156
//
158157
// It requires the server to support the WebDAV MOVE method using an absolute
159158
// path (but not an absolute URL) for the Destination.
160-
func (b *backend) Rename(oldpath string, newpath string) error {
159+
func (b *backend) Rename(oldpath, newpath string) error {
161160
u := b.fullURL(oldpath)
162161
newURL := b.fullURL(newpath)
163162
req, err := http.NewRequest("MOVE", u.String(), nil)
@@ -173,12 +172,11 @@ func (b *backend) Rename(oldpath string, newpath string) error {
173172
if err != nil {
174173
return fmt.Errorf("failed to rename %q to %q: %w", u, newURL, err)
175174
}
175+
_, _ = io.Copy(io.Discard, resp.Body)
176+
_ = resp.Body.Close()
176177
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
177-
resp.Body.Close()
178178
return fmt.Errorf("failed to rename %q to %q: %s", u, newURL, resp.Status)
179179
}
180-
_, _ = io.Copy(io.Discard, resp.Body)
181-
resp.Body.Close()
182180
return nil
183181
}
184182

@@ -194,7 +192,8 @@ func (b *backend) Stat(name string) (fs.FileInfo, error) {
194192
return nil, fmt.Errorf("failed to stat %q: %w", u, err)
195193
}
196194
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
197-
resp.Body.Close()
195+
_, _ = io.Copy(io.Discard, resp.Body)
196+
_ = resp.Body.Close()
198197
return nil, fmt.Errorf("failed to stat %q: %s", u, resp.Status)
199198
}
200199
return &readerInfo{resp: resp}, nil

addons/gocache/http/server/main.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ func main() {
2929
if err != nil {
3030
panic(err)
3131
}
32-
defer os.RemoveAll(td)
32+
defer os.RemoveAll(td) //nolint:errcheck
3333
fmt.Println("Using temporary directory:", td)
3434
tdr, err := os.OpenRoot(td)
3535
if err != nil {
3636
panic(err)
3737
}
38-
defer tdr.Close()
38+
defer tdr.Close() //nolint:errcheck
3939

4040
sigCh := make(chan os.Signal, 1)
4141
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
@@ -63,7 +63,7 @@ func main() {
6363
go func() {
6464
sig := <-sigCh
6565
fmt.Printf("Received %v, shutting down\n", sig)
66-
s.Shutdown(context.TODO())
66+
s.Shutdown(context.TODO()) //nolint:errcheck
6767
}()
6868

6969
if err := s.ListenAndServe(); err != nil {
@@ -133,7 +133,7 @@ func (h *handler) getOrHead(res http.ResponseWriter, req *http.Request, p string
133133
h.errToHTTP(req, res, err)
134134
return
135135
}
136-
defer f.Close()
136+
defer f.Close() //nolint:errcheck
137137
st, err := f.Stat()
138138
if err != nil {
139139
h.err(http.StatusInternalServerError, req, err)
@@ -164,14 +164,20 @@ func (h *handler) put(res http.ResponseWriter, req *http.Request, p string) {
164164
h.errToHTTP(req, res, err)
165165
return
166166
}
167-
defer f.Close()
167+
defer f.Close() //nolint:errcheck
168168
if _, err := io.Copy(f, req.Body); err != nil {
169169
h.err(http.StatusInternalServerError, req, err)
170170
res.WriteHeader(http.StatusInternalServerError)
171-
return
171+
} else if err := f.Sync(); err != nil {
172+
h.err(http.StatusInternalServerError, req, err)
173+
res.WriteHeader(http.StatusInternalServerError)
174+
} else if err := f.Close(); err != nil {
175+
h.err(http.StatusInternalServerError, req, err)
176+
res.WriteHeader(http.StatusInternalServerError)
177+
} else {
178+
res.WriteHeader(http.StatusNoContent)
179+
h.ok(http.StatusNoContent, req)
172180
}
173-
res.WriteHeader(http.StatusNoContent)
174-
h.ok(http.StatusNoContent, req)
175181
}
176182

177183
func (h *handler) delete(res http.ResponseWriter, req *http.Request, p string) {

addons/gocache/rootfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type rootFS struct {
1111
}
1212

1313
func (r *rootFS) FullName(name string) string {
14-
return filepath.Join(r.Root.Name(), name)
14+
return filepath.Join(r.Name(), name)
1515
}
1616

1717
// Open implements DiskDirFS.

magefiles/lint.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"os/exec"
8+
"path/filepath"
79
"sync"
810

911
"github.com/magefile/mage/mg"
@@ -21,6 +23,28 @@ func LintDefault(ctx context.Context) error {
2123
type Lint mg.Namespace
2224

2325
var findGCI = sync.OnceValue(func() string {
26+
gb := os.Getenv("GOBIN")
27+
if gb == "" {
28+
gb = os.Getenv("GOPATH")
29+
if gb == "" {
30+
gb = os.Getenv("HOME") + "/go"
31+
}
32+
gb += "/bin"
33+
}
34+
gbInPath := false
35+
pathVals := os.Getenv("PATH")
36+
for _, dir := range filepath.SplitList(pathVals) {
37+
if dir == gb {
38+
gbInPath = true
39+
break
40+
}
41+
}
42+
if !gbInPath {
43+
// add GOBIN to PATH so that we can find golangci-lint
44+
pathVals += string(os.PathListSeparator) + gb
45+
_ = os.Setenv("PATH", pathVals)
46+
}
47+
2448
if p, err := exec.LookPath("golangci-lint-v2"); err == nil {
2549
return p
2650
}

0 commit comments

Comments
 (0)