Skip to content

Commit

Permalink
refactor: Use sync.OnceValues instead of syncutil.Once
Browse files Browse the repository at this point in the history
  • Loading branch information
bodgit committed Nov 18, 2024
1 parent c865fcb commit 6558fc3
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions internal/aes7z/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"sync"

lru "github.com/hashicorp/golang-lru/v2"
"go4.org/syncutil"
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
)
Expand All @@ -22,17 +22,13 @@ type cacheKey struct {
const cacheSize = 10

//nolint:gochecknoglobals
var (
once syncutil.Once
cache *lru.Cache[cacheKey, []byte]
)
var once = sync.OnceValues(func() (*lru.Cache[cacheKey, []byte], error) {
return lru.New[cacheKey, []byte](cacheSize)
})

func calculateKey(password string, cycles int, salt []byte) ([]byte, error) {
if err := once.Do(func() (err error) {
cache, err = lru.New[cacheKey, []byte](cacheSize)

return
}); err != nil {
cache, err := once()
if err != nil {
return nil, fmt.Errorf("aes7z: error creating cache: %w", err)
}

Expand Down

0 comments on commit 6558fc3

Please sign in to comment.