-
package lru
import (
"sync"
"errors"
"github.com/hashicorp/golang-lru/v2/simplelru"
)
type LRU[K comparable, V any] struct {
lock sync.Mutex
lru *simplelru.LRU[K, V]
}
// NewLRU constructs an LRU of the given size
func NewLRU[K comparable, V any](size int, onEvict simplelru.EvictCallback[K, V]) (*LRU[K, V], error) {
if size <= 0 {
return nil, errors.New("must provide a positive size")
}
c := &LRU[K, V]{
lock: sync.Mutex{},
}
if l, err := simplelru.NewLRU[K, V](size, onEvict); err != nil {
return nil, err
} else {
c.lru = l
}
return c, nil
}
// RemoveOldestN _
func (l *LRU[K, V]) RemoveOldestN(number int) (values []V) {
l.lock.Lock()
defer l.lock.Unlock()
for i := 0; i < number; i++ {
if _, v, ok := l.lru.RemoveOldest(); ok {
values = append(values, v)
} else {
return
}
}
return
} I'm sure the RemoveOldestN method is called somewhere else,But it still errors out |
Beta Was this translation helpful? Give feedback.
Answered by
ldez
Jun 17, 2024
Replies: 1 comment
-
Hello,
I recommend updating your golangci-lint version. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
may11544
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
structcheck
is deprecated, you should not use it.I recommend updating your golangci-lint version.