From e21e309bbb621e95fc00ec2a7a6a59b46040c46b Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 1 Dec 2023 21:14:51 -0800 Subject: [PATCH] Fix some lint --- .github/workflows/lint.yaml | 5 +++++ sloghandler.go | 22 +++++++++++----------- slogr_test.go | 3 ++- slogsink.go | 4 ++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 80b51b5..1a4b7bd 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -11,6 +11,11 @@ jobs: steps: - name: Checkout code uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: Update Go + uses: actions/setup-go@v4 + with: + go-version: '>=1.21.0' + cache: false - name: Lint uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 with: diff --git a/sloghandler.go b/sloghandler.go index 7d13002..f2c96fd 100644 --- a/sloghandler.go +++ b/sloghandler.go @@ -52,7 +52,7 @@ func (l *slogHandler) GetLevel() slog.Level { return l.levelBias } -func (l *slogHandler) Enabled(ctx context.Context, level slog.Level) bool { +func (l *slogHandler) Enabled(_ context.Context, level slog.Level) bool { return l.sink != nil && (level >= slog.LevelError || l.sink.Enabled(l.levelFromSlog(level))) } @@ -107,10 +107,10 @@ func (l *slogHandler) WithAttrs(attrs []slog.Attr) slog.Handler { return l } - copy := *l + clone := *l if l.slogSink != nil { - copy.slogSink = l.slogSink.WithAttrs(attrs) - copy.sink = copy.slogSink + clone.slogSink = l.slogSink.WithAttrs(attrs) + clone.sink = clone.slogSink } else { kvList := make([]any, 0, 2*len(attrs)) for _, attr := range attrs { @@ -118,23 +118,23 @@ func (l *slogHandler) WithAttrs(attrs []slog.Attr) slog.Handler { kvList = append(kvList, l.addGroupPrefix(attr.Key), attr.Value.Resolve().Any()) } } - copy.sink = l.sink.WithValues(kvList...) + clone.sink = l.sink.WithValues(kvList...) } - return © + return &clone } func (l *slogHandler) WithGroup(name string) slog.Handler { if l.sink == nil { return l } - copy := *l + clone := *l if l.slogSink != nil { - copy.slogSink = l.slogSink.WithGroup(name) - copy.sink = copy.slogSink + clone.slogSink = l.slogSink.WithGroup(name) + clone.sink = clone.slogSink } else { - copy.groupPrefix = copy.addGroupPrefix(name) + clone.groupPrefix = clone.addGroupPrefix(name) } - return © + return &clone } func (l *slogHandler) addGroupPrefix(name string) string { diff --git a/slogr_test.go b/slogr_test.go index 9a66628..6c69658 100644 --- a/slogr_test.go +++ b/slogr_test.go @@ -218,7 +218,8 @@ func containsOne(hay string, needles ...string) bool { return false } -func TestDiscard(t *testing.T) { +func TestDiscard(_ *testing.T) { + // Compile-test logger := slog.New(logr.ToSlogHandler(logr.Discard())) logger.WithGroup("foo").With("x", 1).Info("hello") } diff --git a/slogsink.go b/slogsink.go index 93fa4e5..4060fcb 100644 --- a/slogsink.go +++ b/slogsink.go @@ -91,12 +91,12 @@ func (l *slogSink) log(err error, msg string, level slog.Level, kvList ...interf record.AddAttrs(slog.Any(errKey, err)) } record.Add(kvList...) - l.handler.Handle(context.Background(), record) + _ = l.handler.Handle(context.Background(), record) } func (l slogSink) WithName(name string) LogSink { if l.name != "" { - l.name = l.name + "/" + l.name += "/" } l.name += name return &l