Skip to content

Commit 18943fe

Browse files
committed
fix: fix lint error
1 parent 0affa4a commit 18943fe

26 files changed

+153
-125
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v5
1919
with:
20-
go-version: '1.25'
20+
go-version: "1.25"
2121
- name: Login ghcr
2222
uses: docker/login-action@v3
2323
with:
@@ -26,7 +26,7 @@ jobs:
2626
password: ${{ secrets.GITHUB_TOKEN }}
2727
- name: Build
2828
run: |
29-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.48.0
29+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
3030
export PATH=$PATH:$(go env GOPATH)/bin
3131
make check
3232
make build

.golangci.yml

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1-
# https://golangci-lint.run/usage/configuration#config-file
2-
1+
version: "2"
32
linters:
43
enable:
5-
- structcheck
6-
- varcheck
7-
- staticcheck
8-
- unconvert
9-
- gofmt
10-
- goimports
11-
- revive
12-
- ineffassign
13-
- vet
14-
- unused
154
- misspell
5+
- revive
6+
- unconvert
167
disable:
178
- errcheck
18-
19-
run:
20-
deadline: 4m
21-
skip-dirs:
22-
- misc
9+
exclusions:
10+
generated: lax
11+
presets:
12+
- comments
13+
- common-false-positives
14+
- legacy
15+
- std-error-handling
16+
paths:
17+
- third_party$
18+
- builtin$
19+
- examples$
20+
formatters:
21+
enable:
22+
- gofmt
23+
- goimports
24+
exclusions:
25+
generated: lax
26+
paths:
27+
- third_party$
28+
- builtin$
29+
- examples$

cmd/store/main.go

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package main
22

33
import (
44
"fmt"
5+
"log/slog"
56
"os"
67
"os/signal"
7-
"syscall"
8-
"log/slog"
98
"path/filepath"
9+
"syscall"
1010

1111
"github.com/containerd/nydus-snapshotter/cmd/containerd-nydus-grpc/pkg/command"
1212
"github.com/containerd/nydus-snapshotter/config"
@@ -19,7 +19,7 @@ import (
1919
"github.com/containers/nydus-storage-plugin/pkg/services/keychain/dockerconfig"
2020
podmanauth "github.com/containers/nydus-storage-plugin/pkg/services/keychain/podmanauth"
2121
"github.com/containers/nydus-storage-plugin/pkg/services/resolver"
22-
)
22+
)
2323

2424
func waitForSIGINT() {
2525
c := make(chan os.Signal, 1)
@@ -31,27 +31,35 @@ func parseOctalMode(s string) (uint32, error) {
3131
var v uint32
3232
for i := 0; i < len(s); i++ {
3333
c := s[i]
34-
if c < '0' || c > '7' { return 0, fmt.Errorf("invalid octal: %s", s) }
34+
if c < '0' || c > '7' {
35+
return 0, fmt.Errorf("invalid octal: %s", s)
36+
}
3537
v = (v << 3) | uint32(c-'0')
3638
}
3739
return v, nil
3840
}
3941

40-
func setupSlog(level string, toStdout bool, logDir string, root string) error {
42+
func setupSlog(level string, toStdout bool, logDir string) error {
4143
var lvl slog.Level
4244
switch level {
43-
case "debug": lvl = slog.LevelDebug
44-
case "warn", "warning": lvl = slog.LevelWarn
45-
case "error": lvl = slog.LevelError
46-
default: lvl = slog.LevelInfo
45+
case "debug":
46+
lvl = slog.LevelDebug
47+
case "warn", "warning":
48+
lvl = slog.LevelWarn
49+
case "error":
50+
lvl = slog.LevelError
51+
default:
52+
lvl = slog.LevelInfo
4753
}
4854
var w *os.File
4955
if toStdout || logDir == "" {
5056
w = os.Stdout
5157
} else {
5258
path := filepath.Join(logDir, "nydus-store.log")
5359
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
54-
if err != nil { return err }
60+
if err != nil {
61+
return err
62+
}
5563
w = f
5664
}
5765
h := slog.NewTextHandler(w, &slog.HandlerOptions{Level: lvl})
@@ -65,13 +73,13 @@ func main() {
6573
Name: "crio nydus store",
6674
Usage: "crio nydus store plugin",
6775
Version: "0.0.0",
68-
Flags: append(flags.F,
76+
Flags: append(flags.F,
6977
&cli.StringFlag{Name: "fs-file-mode", Usage: "octal file mode for files (e.g. 0400)"},
7078
&cli.StringFlag{Name: "fs-dir-mode", Usage: "octal dir mode (e.g. 0500)"},
7179
&cli.StringFlag{Name: "fs-link-mode", Usage: "octal symlink mode (e.g. 0400)"},
7280
),
7381
Action: func(c *cli.Context) error {
74-
if err := setupSlog(flags.Args.LogLevel, flags.Args.LogToStdout, flags.Args.LogDir, flags.Args.RootDir); err != nil {
82+
if err := setupSlog(flags.Args.LogLevel, flags.Args.LogToStdout, flags.Args.LogDir); err != nil {
7583
return errors.Wrap(err, "failed to prepare logger")
7684
}
7785

@@ -91,7 +99,7 @@ func main() {
9199
dockerconfig.NewDockerconfigKeychain(c.Context),
92100
// Podman-compatible auth.json
93101
podmanauth.NewPodmanAuthKeychain(c.Context),
94-
}...,
102+
}...,
95103
)
96104
layManager, err := manager.NewLayerManager(c.Context, flags.Args.RootDir, hosts, &cfg)
97105
if err != nil {
@@ -103,13 +111,19 @@ func main() {
103111
dirMode := fs.DefaultDirMode()
104112
linkMode := fs.DefaultLinkMode()
105113
if v := c.String("fs-file-mode"); v != "" {
106-
if m, err := parseOctalMode(v); err == nil { fileMode = m }
114+
if m, err := parseOctalMode(v); err == nil {
115+
fileMode = m
116+
}
107117
}
108118
if v := c.String("fs-dir-mode"); v != "" {
109-
if m, err := parseOctalMode(v); err == nil { dirMode = m }
119+
if m, err := parseOctalMode(v); err == nil {
120+
dirMode = m
121+
}
110122
}
111123
if v := c.String("fs-link-mode"); v != "" {
112-
if m, err := parseOctalMode(v); err == nil { linkMode = m }
124+
if m, err := parseOctalMode(v); err == nil {
125+
linkMode = m
126+
}
113127
}
114128

115129
// Recover orphan bind mounts from previous crashes

pkg/cache/lrucache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type LRUCache struct {
2323
// NewLRUCache creates new lru cache.
2424
func NewLRUCache(maxEntries int) *LRUCache {
2525
inner := lru.New(maxEntries)
26-
inner.OnEvicted = func(key lru.Key, value interface{}) {
26+
inner.OnEvicted = func(_ lru.Key, value interface{}) {
2727
// Decrease the ref count incremented in Add().
2828
// When nobody refers to this value, this value will be finalized via refCounter.
2929
value.(*refCounter).finalize()

pkg/fs/blob_file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type blobFile struct {
1414

1515
var _ = (fusefs.FileReader)((*blobFile)(nil))
1616

17-
func (f *blobFile) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) {
17+
func (f *blobFile) Read(_ context.Context, _ []byte, _ int64) (fuse.ReadResult, syscall.Errno) {
1818
//s, err := f.l.ReadAt(dest, off,
1919
// remote.WithContext(ctx), // Make cancellable
2020
// remote.WithCacheOpts(cache.Direct()), // Do not pollute mem cache
@@ -28,7 +28,7 @@ func (f *blobFile) Read(ctx context.Context, dest []byte, off int64) (fuse.ReadR
2828

2929
var _ = (fusefs.FileGetattrer)((*blobFile)(nil))
3030

31-
func (f *blobFile) Getattr(ctx context.Context, out *fuse.AttrOut) syscall.Errno {
31+
func (f *blobFile) Getattr(_ context.Context, _ *fuse.AttrOut) syscall.Errno {
3232
//layerToAttr(f.l, &out.Attr)
3333
return 0
3434
}

pkg/fs/blob_file_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import (
99

1010
func TestBlobFileReadEIO(t *testing.T) {
1111
bf := &blobFile{}
12-
if rr, eno := bf.Read(context.Background(), nil, 0); eno == 0 || rr != nil {
12+
if rr, eno := bf.Read(context.Background(), nil, 0); eno == 0 || rr != nil {
1313
t.Fatalf("expected EIO and nil read result, got eno=%d rr=%v", eno, rr)
1414
}
1515
}
1616

1717
func TestBlobFileGetattrNoError(t *testing.T) {
1818
bf := &blobFile{}
1919
var out fuse.AttrOut
20-
if eno := bf.Getattr(context.Background(), &out); eno != 0 {
20+
if eno := bf.Getattr(context.Background(), &out); eno != 0 {
2121
t.Fatalf("Getattr returned errno=%d", eno)
2222
}
2323
}

pkg/fs/blob_node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ var _ = (fusefs.InodeEmbedder)((*blobNode)(nil))
2020

2121
var _ = (fusefs.NodeOpener)((*blobNode)(nil))
2222

23-
func (n *blobNode) Open(ctx context.Context, flags uint32) (fh fusefs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
23+
func (n *blobNode) Open(_ context.Context, _ uint32) (fh fusefs.FileHandle, fuseFlags uint32, errno syscall.Errno) {
2424
return &blobFile{}, 0, 0
2525
}

pkg/fs/blob_node_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func TestBlobNodeOpenReturnsBlobFile(t *testing.T) {
99
n := &blobNode{}
10-
fh, _, eno := n.Open(context.Background(), 0)
10+
fh, _, eno := n.Open(context.Background(), 0)
1111
if eno != 0 {
1212
t.Fatalf("Open errno=%d", eno)
1313
}

pkg/fs/diff_node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type diffNode struct {
1515
fs *fs
1616
}
1717

18-
func (n *diffNode) Getattr(ctx context.Context, f fusefs.FileHandle, out *fuse.AttrOut) syscall.Errno {
18+
func (n *diffNode) Getattr(_ context.Context, _ fusefs.FileHandle, out *fuse.AttrOut) syscall.Errno {
1919
copyAttr(&out.Attr, &n.attr)
2020
return 0
2121
}

pkg/fs/diff_node_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ func TestDiffNodeGetattrCopiesAttr(t *testing.T) {
1414
if eno := d.Getattr(context.Background(), nil, &out); eno != 0 {
1515
t.Fatalf("Getattr errno=%d", eno)
1616
}
17-
if out.Attr.Mode != d.attr.Mode {
18-
t.Fatalf("mode mismatch: got %o want %o", out.Attr.Mode, d.attr.Mode)
17+
if out.Mode != d.attr.Mode {
18+
t.Fatalf("mode mismatch: got %o want %o", out.Mode, d.attr.Mode)
1919
}
2020
}
2121

0 commit comments

Comments
 (0)