A simple and efficient URL shortener service built with Go, PostgreSQL, and DiceDB (in-memory cache).
- Shorten URLs easily.
- Persistent storage with PostgreSQL.
- High-speed caching with DiceDB.
- Ready-to-use Docker setup for easy deployment.
- Copy the sample config file:
cp config.sample.json config.json- Update
config.jsonwith your PostgreSQL and DiceDB connection details if needed.
Simply run:
go run main.goThis will start the URL shortener server on localhost:8081.
- Endpoint:
POST http://localhost:8081/url - Payload:
{
"original-url": "https://example-url.com"
}- Response:
{
"short-url": "http://localhost:8081/000003"
}A Dockerfile is included to containerize the application.
docker build -t urlshortener .
docker run -p 8081:8081 urlshortenerIf you want to run PostgreSQL, DiceDB, and the URL shortener together:
cd docker
docker-compose up -dThis will:
- Start a PostgreSQL container.
- Start a DiceDB container.
- Start the URL Shortener service.
All services will be ready and connected automatically.
This project is deployed on:
Note: There is a rate limit of 3 requests per minute for creating a short URL.
├── main.go
├── config.sample.json
├── config.json (after you create it)
├── Dockerfile
├── docker/
│ └── docker-compose.yml
├── internal/ (application code)
└── README.md
- Go 1.24+
- Docker (optional but recommended)