A Go-based service that resizes images from provided URLs and serves them through a REST API. The service supports both synchronous and asynchronous processing modes.
- Resize images from any public URL
 - Support for both synchronous and asynchronous processing
 - LRU caching for processed images
 - Configurable timeouts and processing delays
 - Browser-like User-Agent for better compatibility
 
- Go 1.16 or later
 - Air (for development with hot reload)
 - HTTPie (for testing, or use curl)
 
- Clone the repository:
 
git clone https://github.com/cmin764/image-resize.git
cd image-resize- Install Air for development:
 
go install github.com/air-verse/air@latest- Install project dependencies:
 
go mod downloadCreate a .env file in the project root by copying the template:
cp .env.template .envThen edit the .env file with the following settings:
# Image processing timeout in seconds (how long to wait for an image to be processed)
IMAGE_PROCESSING_TIMEOUT=1
# Simulated processing duration in seconds (for testing)
IMAGE_PROCESSING_DURATION=3# Try this first
air
# If the above doesn't work, use the full path
~/go/bin/airgo run .The server will start on http://localhost:8080
Send a POST request to /v1/resize with a JSON body containing the image URLs and desired dimensions:
# Synchronous mode (default)
http POST ":8080/v1/resize" @data/req.json
# Asynchronous mode
http POST ":8080/v1/resize?async=true" @data/req.jsonExample request body:
{
  "urls": [
    "https://example.com/image1.jpg",
    "https://example.com/image2.jpg"
  ],
  "width": 200,
  "height": 0  // 0 maintains aspect ratio
}After processing, access the resized images at:
http://localhost:8080/v1/image/{image-id}.jpeg- Returns:
200 OKwhen all images are served straight from the cache201 Createdwhen new images are processed and saved to cache
 
- Returns 
202 Acceptedimmediately (later processing) 
Check individual image URLs for status.
102 Processing: Image is still being processed200 OK: Image is ready and retrieved404 Not Found: Image processing failed and not found in the cache
- Send resize request:
 
http POST ":8080/v1/resize?async=true" @data/req.json- Check image status:
 
http http://localhost:8080/v1/image/AQPdOTElKSNH_piyJSCR4p1yMMRC1omE-mClICKUoks=.jpegIf status is
102, wait and retry until you get200(or a404if the process failed in the meantime)
See improvements for a list of potential fixes, including:
- Adding comprehensive test coverage
 - Performance optimizations
 - Security enhancements
 - Additional features
 - Infrastructure improvements