A simple yet powerful URL Shortener service built with Golang, PostgreSQL, and Goose migrations. This project allows users to shorten long URLs, manage their own links, and ensures that each shortened URL is securely associated with the authenticated user who created it.
-
🔐 User Authentication
- Secure user registration and login
- Token-based authentication (JWT)
- Only logged-in users can create and manage URLs
-
✂️ URL Shortening
- Generate short, unique URLs for any valid link
- Automatically map each shortened URL to the user who created it
-
📊 User-specific Data
- Users can view and manage only their own shortened URLs
- Prevents cross-user access to private data
- Backend: Golang
- Database: PostgreSQL
- Migrations: Goose
- ORM / Queries: sqlc
- Authentication: JWT
git clone https://github.com/Udayan853/url-shortener.git
cd url-shortenergo mod tidyMake sure you have PostgreSQL running locally or remotely. Create a new database:
CREATE DATABASE url_shortener;goose -dir ./sql/schema postgres "postgres://user:password@localhost:5432/url_shortener?sslmode=disable" upgo run main.goServer will start at http://localhost:8080
docker pull udayank23/url-shortener:latest
docker run -d -p 8080:8080 --env-file .env udayank23/url-shortener:latestServer will start at http://localhost:8080
POST /api/users→ Register new userPOST /api/login→ Login user and return JWT
POST /api/shorten→ Shorten a URL (requires authentication)GET /api/urls→ List all URLs for logged-in userGET /api/:short_code→ Redirect to the original URL
curl -X POST http://localhost:8080/api/shorten \
-H "Authorization: Bearer <JWT_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/very/long/link", "custom_alias":"abc123"}'Response:
{
"short_code": "abc123",
"original_url": "https://example.com/very/long/link"
}- Frontend interface for easier management
- Background Job Queue for asynchronous processing of analytics
- Cron Job to remove expired shortened
urls - Add Oauth for SSO (Google, Github, etc)
Pull requests are welcome! If you’d like to contribute, feel free to fork the repo and submit a PR.