Skip to content

Commit

Permalink
Fix some lint
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Dec 4, 2023
1 parent ff10a9b commit e21e309
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 11 additions & 11 deletions sloghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}

Expand Down Expand Up @@ -107,34 +107,34 @@ 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 {
if attr.Key != "" {
kvList = append(kvList, l.addGroupPrefix(attr.Key), attr.Value.Resolve().Any())
}
}
copy.sink = l.sink.WithValues(kvList...)
clone.sink = l.sink.WithValues(kvList...)
}
return &copy
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 &copy
return &clone
}

func (l *slogHandler) addGroupPrefix(name string) string {
Expand Down
3 changes: 2 additions & 1 deletion slogr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions slogsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e21e309

Please sign in to comment.