122b0f4926b93ccaaa29ba5156c13ceba335cbdd
Link Shortener
A simple and fast URL shortener service built with Go and Redis.
Features
- Shorten long URLs into compact short links
- Redirect short links to original URLs
- 30-day expiration for stored links
Getting Started
Prerequisites
- Docker and Docker Compose
Installation & Running
- Clone the repository:
git clone https://github.com/dusiburg/link-shortener
cd link-shortener
- Start the application with docker compose:
docker compose up
The service will be available at http://localhost:8080
API Endpoints
Create Short Link
Request:
GET /l/{original-url}
Example:
curl "http://localhost:8080/l/https://example.com/very/long/url"
Response:
{
"status": "success",
"short_link": "http://localhost:8080/r/abc123xyz",
"original_link": "https://example.com/very/long/url",
"expires_in": "30d"
}
Redirect to Original Link
Request:
GET /r/{short-id}
Example:
curl "http://localhost:8080/r/abc123xyz"
This will redirect to the original URL.
Health Check
Request:
GET /ping
Response:
{
"status": "success"
}
Configuration
Environment variables can be set via .env file or docker compose:
SERVER_HOST- Server host (default:localhost)SERVER_PORT- Server port (default:8080)REDIS_URL- Redis connection URL (required)
Project Structure
.
├── cmd/
│ └── main.go # Application entry point
├── internal/
│ ├── config/ # Configuration management
│ ├── db/ # Database connections
│ ├── handlers/ # HTTP request handlers
│ ├── http/ # HTTP server setup
│ ├── repositories/ # Data access layer
│ └── services/ # Business logic
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Multi-stage Docker build
└── README # This file
Development
To build locally without Docker:
go build -o bin/application ./cmd
./bin/application
Make sure Redis is running before starting the application.
Description
Languages
Go
100%