Thanks to visit codestin.com
Credit goes to github.com

Skip to content

tetsuo/resizer

Repository files navigation

resizer

Image resizing service.

thumbs-up

Build

go build -o bin/resizer ./cmd/resizer

Usage

Usage 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)

API

POST /v1/resize

Submit images for resizing.

Query params:

  • async=true - returns immediately
  • timeout=<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/https only
  • At least one dimension must be > 0
  • No self-referencing URLs

Error responses: 400 (validation), 405 (method), 413 (body size), 408 (timeout)

GET /v1/image/{filename}

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.

Architecture

Processor (internal/processor/)

Downloads and resizes images. Manages cache. SHA256 hashing for filenames.

Tracker (internal/tracker/)

Tracks processing state per hash. Per-hash mutex locks for concurrency. Notifies waiting requests on completion.

Tests

go test -v ./...

About

Image resizing service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages