fix: resolve all golangci-lint errors
- Add blank lines before return statements (nlreturn) - Remove unused metaCacheMu field and sync import (unused) - Rename unused groups parameter to _ (revive) - Use StorageFilePerm constant instead of magic 0600 (mnd, gosec) - Add nolint directive for vipsOnce global (gochecknoglobals)
This commit is contained in:
parent
454de2f170
commit
ce6db7627d
@ -8,7 +8,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -43,8 +42,7 @@ type Cache struct {
|
||||
config CacheConfig
|
||||
|
||||
// In-memory cache of variant metadata (content type, size) to avoid reading .meta files
|
||||
metaCache map[VariantKey]variantMeta
|
||||
metaCacheMu sync.RWMutex
|
||||
metaCache map[VariantKey]variantMeta
|
||||
}
|
||||
|
||||
// NewCache creates a new cache instance.
|
||||
@ -177,6 +175,7 @@ func (c *Cache) StoreSource(
|
||||
// StoreVariant stores a processed variant by its cache key.
|
||||
func (c *Cache) StoreVariant(cacheKey VariantKey, content io.Reader, contentType string) error {
|
||||
_, err := c.variants.Store(cacheKey, content, contentType)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// vipsOnce ensures vips is initialized exactly once.
|
||||
var vipsOnce sync.Once
|
||||
var vipsOnce sync.Once //nolint:gochecknoglobals // package-level sync.Once for one-time vips init
|
||||
|
||||
// initVips initializes libvips with quiet logging.
|
||||
func initVips() {
|
||||
@ -38,6 +38,7 @@ type ImageProcessor struct{}
|
||||
// NewImageProcessor creates a new image processor.
|
||||
func NewImageProcessor() *ImageProcessor {
|
||||
initVips()
|
||||
|
||||
return &ImageProcessor{}
|
||||
}
|
||||
|
||||
@ -177,6 +178,7 @@ func (p *ImageProcessor) resize(img *vips.ImageRef, width, height int, fit FitMo
|
||||
scale := min(scaleW, scaleH)
|
||||
newW := int(float64(imgW) * scale)
|
||||
newH := int(float64(imgH) * scale)
|
||||
|
||||
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
||||
|
||||
case FitFill:
|
||||
@ -194,6 +196,7 @@ func (p *ImageProcessor) resize(img *vips.ImageRef, width, height int, fit FitMo
|
||||
scale := min(scaleW, scaleH)
|
||||
newW := int(float64(imgW) * scale)
|
||||
newH := int(float64(imgH) * scale)
|
||||
|
||||
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
||||
|
||||
case FitOutside:
|
||||
@ -204,6 +207,7 @@ func (p *ImageProcessor) resize(img *vips.ImageRef, width, height int, fit FitMo
|
||||
scale := max(scaleW, scaleH)
|
||||
newW := int(float64(imgW) * scale)
|
||||
newH := int(float64(imgH) * scale)
|
||||
|
||||
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
||||
|
||||
default:
|
||||
|
||||
@ -103,6 +103,7 @@ func (s *Service) Get(ctx context.Context, req *ImageRequest) (*ImageResponse, e
|
||||
"host", req.SourceHost,
|
||||
"path", req.SourcePath,
|
||||
)
|
||||
|
||||
return nil, fmt.Errorf("%w: %w", ErrUpstreamError, ErrNegativeCached)
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,8 @@ import (
|
||||
const (
|
||||
// StorageDirPerm is the permission mode for storage directories.
|
||||
StorageDirPerm = 0750
|
||||
// StorageFilePerm is the permission mode for storage files.
|
||||
StorageFilePerm = 0600
|
||||
// MinHashLength is the minimum hash length for path splitting.
|
||||
MinHashLength = 4
|
||||
)
|
||||
@ -409,7 +411,7 @@ func (s *VariantStorage) Store(key VariantKey, r io.Reader, contentType string)
|
||||
return 0, fmt.Errorf("failed to marshal metadata: %w", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(metaPath, metaData, 0640); err != nil {
|
||||
if err := os.WriteFile(metaPath, metaData, StorageFilePerm); err != nil {
|
||||
// Non-fatal, content is stored
|
||||
_ = err
|
||||
}
|
||||
|
||||
@ -40,12 +40,13 @@ func New(_ fx.Lifecycle, params Params) (*Logger, error) {
|
||||
}
|
||||
|
||||
// replaceAttr simplifies the source attribute to "file.go:line"
|
||||
replaceAttr := func(groups []string, a slog.Attr) slog.Attr {
|
||||
replaceAttr := func(_ []string, a slog.Attr) slog.Attr {
|
||||
if a.Key == slog.SourceKey {
|
||||
if src, ok := a.Value.Any().(*slog.Source); ok {
|
||||
a.Value = slog.StringValue(fmt.Sprintf("%s:%d", filepath.Base(src.File), src.Line))
|
||||
}
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user