Skip to content

Commit 8b95ca5

Browse files
[cache-processor] chore: Lint and modernize (#47347) (#47887)
In preparation for #46985. I ran ```sh go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./libbeat/processors/cache golangci-lint run --fix ./libbeat/processors/cache ``` and fixed any errors. (cherry picked from commit 050f433) Co-authored-by: Orestis Floros <[email protected]>
1 parent fa0b370 commit 8b95ca5

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

libbeat/processors/cache/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (p *cache) getFor(event *beat.Event) (result *beat.Event, err error) {
274274
if meta == nil {
275275
return nil, fmt.Errorf("%w for '%s' in %s", ErrNoData, k, p.store)
276276
}
277-
if m, ok := meta.(map[string]interface{}); ok {
277+
if m, ok := meta.(map[string]any); ok {
278278
meta = mapstr.M(m)
279279
}
280280
// ... and write it into the event.

libbeat/processors/cache/cache_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727

2828
"github.com/elastic/beats/v7/libbeat/beat"
2929
conf "github.com/elastic/elastic-agent-libs/config"
30-
"github.com/elastic/elastic-agent-libs/logp"
3130
"github.com/elastic/elastic-agent-libs/logp/logptest"
3231
"github.com/elastic/elastic-agent-libs/mapstr"
3332
"github.com/elastic/elastic-agent-libs/paths"
@@ -645,7 +644,6 @@ type testConfig struct {
645644
}
646645

647646
func TestCache(t *testing.T) {
648-
logp.TestingSetup(logp.WithSelectors(name))
649647
for _, test := range cacheTests {
650648
t.Run(test.name, func(t *testing.T) {
651649
var processors []beat.Processor
@@ -687,7 +685,6 @@ func TestCache(t *testing.T) {
687685
t.Errorf("unexpected error from c.Close(): %v", err)
688686
}
689687
}()
690-
691688
processors = append(processors, p)
692689
}
693690

libbeat/processors/cache/file_store.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ func (c *fileStore) readState() {
191191
var e CacheEntry
192192
err = dec.Decode(&e)
193193
if err != nil {
194-
if err != io.EOF {
195-
switch err := err.(type) {
196-
case *json.SyntaxError:
194+
if !errors.Is(err, io.EOF) {
195+
var err *json.SyntaxError
196+
switch {
197+
case errors.As(err, &err):
197198
c.log.Errorw("failed to read state element", "error", err, "path", c.path, "offset", err.Offset)
198199
default:
199200
c.log.Errorw("failed to read state element", "error", err, "path", c.path)

libbeat/processors/cache/file_store_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ func TestFileStore(t *testing.T) {
513513
var e CacheEntry
514514
err = dec.Decode(&e)
515515
if err != nil {
516-
if err != io.EOF {
516+
if !errors.Is(err, io.EOF) {
517517
t.Fatalf("unexpected error reading persisted cache data: %v", err)
518518
}
519519
break

libbeat/processors/cache/mem_store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ var _ heap.Interface = (*expiryHeap)(nil)
237237
type expiryHeap []*CacheEntry
238238

239239
func (h *expiryHeap) pop() *CacheEntry {
240-
e := heap.Pop(h).(*CacheEntry)
240+
e := heap.Pop(h).(*CacheEntry) //nolint:errcheck // Should never happen, panicing here is preferred
241241
e.index = -1
242242
return e
243243
}
@@ -254,7 +254,7 @@ func (h expiryHeap) Swap(i, j int) {
254254
h[j].index = j
255255
}
256256
func (h *expiryHeap) Push(v any) {
257-
e := v.(*CacheEntry)
257+
e := v.(*CacheEntry) //nolint:errcheck // Should never happen, panicing here is preferred
258258
e.index = len(*h)
259259
*h = append(*h, e)
260260
}

0 commit comments

Comments
 (0)