Refactor: split internal/imgcache into focused packages #39
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Per PR #37 discussion,
internal/imgcache/currently bundles many distinct concerns into a single package. This issue tracks splitting it into focused, independently testable packages.Already Done
internal/imageprocessor/— Image format conversion and resizing (extracted in PR #37)Easily Separable
These have minimal coupling to the core cache/service layer and can be extracted with straightforward interface boundaries:
fetcher (
fetcher.go) →internal/httpfetcher/HTTPFetcher,FetcherConfig,DefaultFetcherConfig, SSRF-safe dialer, rate limiting, content-type validationFetcherinterface andFetchResulttype inimgcache.gomock_fetcher.gocan move with it or stay as a test helpersignature (
signature.go) →internal/signature/Signer,NewSigner,Sign,Verify,GenerateSignedURL,ParseSignatureParamsImageRequestfor building the HMAC payloadmagic (
magic.go) →internal/magic/MIMEType,DetectFormat,ValidateMagicBytes,PeekAndValidate,IsSupportedMIMEType,MIMEToImageFormat,ImageFormatToMIMEImageFormattype constantswhitelist (
whitelist.go) →internal/whitelist/HostWhitelist,NewHostWhitelist,IsWhitelisted,IsEmpty,Countnet/urlandstringsurlparser (
urlparser.go) →internal/urlparser/ParsedURL,ParseImagePath,ParseImageURL, path traversal validation, size/format parsingImageRequest,Size,ImageFormat,FitMode— would need to import shared typesTightly Coupled (keep together)
These share significant state and data flow with the service orchestrator. Splitting them further would require significant interface surgery and may not be worth it:
cache.go) — Cache lookup, variant storage, negative cache, stats. Tightly coupled withservice.goandstorage.go.storage.go) — Content-addressedContentStorageandMetadataStorage. Created and managed byCache.service.go) — The core orchestrator that wires cache, fetcher, and processor together.imgcache.go) —ImageRequest,ImageResponse,ImageFormat,FitMode,Size, etc. These are the shared vocabulary used across all subpackages.Approach
Each extraction should:
internal/docker build .passes (fmt, lint, test, build)