mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
* Implement static analysis to prevent panics * Add nopanic to nogo * Fix violations and add exclusions Fix violations and add exclusions for all * Changelog fragment * Use pass.Report instead of pass.Reportf * Remove strings.ToLower for checking init method name * Add exclusion for herumi init * Move api/client/beacon template function to init and its own file * Fix nopanic testcase
27 lines
665 B
Go
27 lines
665 B
Go
package lru
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
lru "github.com/hashicorp/golang-lru"
|
|
)
|
|
|
|
// New creates an LRU of the given size.
|
|
func New(size int) *lru.Cache {
|
|
cache, err := lru.New(size)
|
|
if err != nil {
|
|
panic(fmt.Errorf("lru new failed: %w", err)) // lint:nopanic -- This should never panic.
|
|
}
|
|
return cache
|
|
}
|
|
|
|
// NewWithEvict constructs a fixed size cache with the given eviction
|
|
// callback.
|
|
func NewWithEvict(size int, onEvicted func(key interface{}, value interface{})) *lru.Cache {
|
|
cache, err := lru.NewWithEvict(size, onEvicted)
|
|
if err != nil {
|
|
panic(fmt.Errorf("lru new with evict failed: %w", err)) // lint:nopanic -- This should never panic.
|
|
}
|
|
return cache
|
|
}
|