A minimal URL shortener service written in Go. Stores mappings in memory and exposes a small JSON/HTTP API.
- Go 1.22+
make run
# or
go run ./cmd/serverThe server listens on :8080 by default; override with the ADDR environment
variable.
| Method | Path | Description |
|---|---|---|
| POST | /shorten |
Shorten a URL. Body: {"url": "https://…"} |
| GET | /{code} |
Redirect to the original URL |
| GET | /healthz |
Health check |
Example:
curl -s -X POST localhost:8080/shorten -d '{"url":"https://example.com"}'
# {"code":"aB3xY9z"}
curl -i localhost:8080/aB3xY9z
# HTTP/1.1 302 Foundmake test # run tests
make lint # go vet
make build # build binary into bin/cmd/server— application entrypointinternal/shortener— HTTP handlers and shortening logicinternal/storage— storage interface and in-memory implementation