Image resizing service.
go build -o bin/resizer ./cmd/resizerUsage of resizer:
-addr string
address to listen on (default "localhost:8080")
-cache-origdir string
directory for original images (default "cache/orig")
-cache-outdir string
directory for resized images (default "cache/output")
-client-timeout duration
http client timeout (default 10s)
-request-timeout duration
request timeout when not provided (default 30s)Submit images for resizing.
Query params:
async=true- returns immediatelytimeout=<seconds>- overrides default request timeout
Request:
{
"urls": ["http://example.com/image.jpg"],
"width": 800,
"height": 600
}Response (201):
[
{
"result": "success",
"source": "http://example.com/image.jpg",
"url": "http://localhost:8080/v1/image/Xj8K...Qw.800x600.jpg",
"cached": true
},
{
"result": "failure",
"source": "http://example.com/notfoundimage.jpg",
"reason":"HTTP 404: 404 File not found",
"cached": false
}
]In blocking mode (default), waits for processing to complete, returns results when done or timeout.
In async mode (?async=true), returns results immediately, always with success.
Constraints:
- Max 100 URLs per request
- Max 1MB request body
- Max 9999×9999 dimensions
- Max 1000 chars per URL
http/httpsonly- At least one dimension must be > 0
- No self-referencing URLs
Error responses: 400 (validation), 405 (method), 413 (body size), 408 (timeout)
Retrieve resized image.
Path format: {sha256_hash}.{width}x{height}.{ext}
Example: /v1/image/Xj8KLm9pQw.800x600.jpg
Query params:
timeout=<seconds>- overrides default request timeout
Returns:
- 200 with image
- 404 if not found or not processing
- 408 if processing timeout
- 500 if processing failed
Path constraints: max 57 chars, alphanumeric/dots/hyphens/underscores only, .jpg or .png extensions.
Downloads and resizes images. Manages cache. SHA256 hashing for filenames.
Tracks processing state per hash. Per-hash mutex locks for concurrency. Notifies waiting requests on completion.
go test -v ./...