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:
@@ -8,7 +8,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,7 +43,6 @@ type Cache struct {
|
|||||||
|
|
||||||
// In-memory cache of variant metadata (content type, size) to avoid reading .meta files
|
// In-memory cache of variant metadata (content type, size) to avoid reading .meta files
|
||||||
metaCache map[VariantKey]variantMeta
|
metaCache map[VariantKey]variantMeta
|
||||||
metaCacheMu sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCache creates a new cache instance.
|
// NewCache creates a new cache instance.
|
||||||
@@ -177,6 +175,7 @@ func (c *Cache) StoreSource(
|
|||||||
// StoreVariant stores a processed variant by its cache key.
|
// StoreVariant stores a processed variant by its cache key.
|
||||||
func (c *Cache) StoreVariant(cacheKey VariantKey, content io.Reader, contentType string) error {
|
func (c *Cache) StoreVariant(cacheKey VariantKey, content io.Reader, contentType string) error {
|
||||||
_, err := c.variants.Store(cacheKey, content, contentType)
|
_, err := c.variants.Store(cacheKey, content, contentType)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// vipsOnce ensures vips is initialized exactly once.
|
// 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.
|
// initVips initializes libvips with quiet logging.
|
||||||
func initVips() {
|
func initVips() {
|
||||||
@@ -38,6 +38,7 @@ type ImageProcessor struct{}
|
|||||||
// NewImageProcessor creates a new image processor.
|
// NewImageProcessor creates a new image processor.
|
||||||
func NewImageProcessor() *ImageProcessor {
|
func NewImageProcessor() *ImageProcessor {
|
||||||
initVips()
|
initVips()
|
||||||
|
|
||||||
return &ImageProcessor{}
|
return &ImageProcessor{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,6 +178,7 @@ func (p *ImageProcessor) resize(img *vips.ImageRef, width, height int, fit FitMo
|
|||||||
scale := min(scaleW, scaleH)
|
scale := min(scaleW, scaleH)
|
||||||
newW := int(float64(imgW) * scale)
|
newW := int(float64(imgW) * scale)
|
||||||
newH := int(float64(imgH) * scale)
|
newH := int(float64(imgH) * scale)
|
||||||
|
|
||||||
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
||||||
|
|
||||||
case FitFill:
|
case FitFill:
|
||||||
@@ -194,6 +196,7 @@ func (p *ImageProcessor) resize(img *vips.ImageRef, width, height int, fit FitMo
|
|||||||
scale := min(scaleW, scaleH)
|
scale := min(scaleW, scaleH)
|
||||||
newW := int(float64(imgW) * scale)
|
newW := int(float64(imgW) * scale)
|
||||||
newH := int(float64(imgH) * scale)
|
newH := int(float64(imgH) * scale)
|
||||||
|
|
||||||
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
||||||
|
|
||||||
case FitOutside:
|
case FitOutside:
|
||||||
@@ -204,6 +207,7 @@ func (p *ImageProcessor) resize(img *vips.ImageRef, width, height int, fit FitMo
|
|||||||
scale := max(scaleW, scaleH)
|
scale := max(scaleW, scaleH)
|
||||||
newW := int(float64(imgW) * scale)
|
newW := int(float64(imgW) * scale)
|
||||||
newH := int(float64(imgH) * scale)
|
newH := int(float64(imgH) * scale)
|
||||||
|
|
||||||
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
return img.Thumbnail(newW, newH, vips.InterestingNone)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -103,6 +103,7 @@ func (s *Service) Get(ctx context.Context, req *ImageRequest) (*ImageResponse, e
|
|||||||
"host", req.SourceHost,
|
"host", req.SourceHost,
|
||||||
"path", req.SourcePath,
|
"path", req.SourcePath,
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil, fmt.Errorf("%w: %w", ErrUpstreamError, ErrNegativeCached)
|
return nil, fmt.Errorf("%w: %w", ErrUpstreamError, ErrNegativeCached)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
// StorageDirPerm is the permission mode for storage directories.
|
// StorageDirPerm is the permission mode for storage directories.
|
||||||
StorageDirPerm = 0750
|
StorageDirPerm = 0750
|
||||||
|
// StorageFilePerm is the permission mode for storage files.
|
||||||
|
StorageFilePerm = 0600
|
||||||
// MinHashLength is the minimum hash length for path splitting.
|
// MinHashLength is the minimum hash length for path splitting.
|
||||||
MinHashLength = 4
|
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)
|
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
|
// Non-fatal, content is stored
|
||||||
_ = err
|
_ = err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,12 +40,13 @@ func New(_ fx.Lifecycle, params Params) (*Logger, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replaceAttr simplifies the source attribute to "file.go:line"
|
// 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 a.Key == slog.SourceKey {
|
||||||
if src, ok := a.Value.Any().(*slog.Source); ok {
|
if src, ok := a.Value.Any().(*slog.Source); ok {
|
||||||
a.Value = slog.StringValue(fmt.Sprintf("%s:%d", filepath.Base(src.File), src.Line))
|
a.Value = slog.StringValue(fmt.Sprintf("%s:%d", filepath.Base(src.File), src.Line))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user