Add golangci-lint config

This commit is contained in:
2026-02-12 02:54:35 +03:00
parent f22111aa43
commit 9e59fa18e4
14 changed files with 112 additions and 50 deletions

View File

@@ -2,6 +2,7 @@ package cacher
import (
"crypto/md5"
"encoding/hex"
"fmt"
"os"
"path/filepath"
@@ -31,7 +32,7 @@ func (c *Cacher) getFile(sourcePath string) (*models.CacheItem, error) {
keyData := fmt.Sprintf("%s:%d", sourcePath, sourceFileInfo.ModTime().UnixNano())
hash := md5.Sum([]byte(keyData))
cacheKey := fmt.Sprintf("%x", hash)
cacheKey := hex.EncodeToString(hash[:])
cacheFilePath := filepath.Join(c.cacheDir, cacheKey+".m4a")
c.itemsMutex.Lock()
@@ -73,6 +74,7 @@ func (c *Cacher) getFile(sourcePath string) (*models.CacheItem, error) {
// File does not exist on disk, need to transcode.
// Register in the queue
c.transcoder.QueueChannel() <- struct{}{}
defer func() {
<-c.transcoder.QueueChannel()
}()
@@ -94,7 +96,7 @@ func (c *Cacher) getFile(sourcePath string) (*models.CacheItem, error) {
c.updateCachedStat(sourcePath, size)
// TODO: run cleanup on inotify events.
// c.cleanup()
c.cleanup()
return item, nil
}

View File

@@ -2,6 +2,7 @@ package cacher
import (
"crypto/md5"
"encoding/hex"
"fmt"
"os"
"path/filepath"
@@ -10,7 +11,7 @@ import (
"source.hodakov.me/hdkv/faketunes/internal/domains/cacher/models"
)
// getStat returns file size without triggering conversion (for ls/stat)
// getStat returns file size without triggering conversion (for ls/stat).
func (c *Cacher) GetStat(sourcePath string) (int64, error) {
c.statMutex.RLock()
defer c.statMutex.RUnlock()
@@ -28,7 +29,7 @@ func (c *Cacher) GetStat(sourcePath string) (int64, error) {
keyData := fmt.Sprintf("%s:%d", sourcePath, info.ModTime().UnixNano())
hash := md5.Sum([]byte(keyData))
key := fmt.Sprintf("%x", hash)
key := hex.EncodeToString(hash[:])
cachePath := filepath.Join(c.cacheDir, key+".m4a")
// Check if converted file exists and is valid
@@ -44,7 +45,7 @@ func (c *Cacher) GetStat(sourcePath string) (int64, error) {
return info.Size(), nil
}
// updateCachedStat updates the stat cache
// updateCachedStat updates the stat cache.
func (c *Cacher) updateCachedStat(sourcePath string, size int64) {
c.statMutex.Lock()
defer c.statMutex.Unlock()
@@ -55,7 +56,7 @@ func (c *Cacher) updateCachedStat(sourcePath string, size int64) {
}
}
// getCachedStat returns cached file stats
// getCachedStat returns cached file stats.
func (c *Cacher) getCachedStat(sourcePath string) (int64, bool) {
c.statMutex.RLock()
defer c.statMutex.RUnlock()
@@ -63,5 +64,6 @@ func (c *Cacher) getCachedStat(sourcePath string) (int64, bool) {
if stat, ok := c.stat[sourcePath]; ok {
return stat.Size, true
}
return 0, false
}