https://github.com/telman03/go-url-shortener
A high-performance URL shortener built with Golang (Fiber), PostgreSQL, and Redis for caching. It supports click tracking for analytics, and is designed with scalability in mind.
https://github.com/telman03/go-url-shortener
docker-compose fiber go postgresql redis
Last synced: 2 months ago
JSON representation
A high-performance URL shortener built with Golang (Fiber), PostgreSQL, and Redis for caching. It supports click tracking for analytics, and is designed with scalability in mind.
- Host: GitHub
- URL: https://github.com/telman03/go-url-shortener
- Owner: telman03
- Created: 2025-02-25T21:41:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-25T21:49:45.000Z (over 1 year ago)
- Last Synced: 2025-07-02T17:44:55.292Z (about 1 year ago)
- Topics: docker-compose, fiber, go, postgresql, redis
- Language: Go
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# URL Shortener
## 📌 Overview
This is a high-performance **URL shortener** built with **Golang (Fiber)**, **PostgreSQL**, **Redis**, and **Docker**. It allows users to shorten long URLs, track click analytics, and retrieve stored URLs efficiently.
## 🚀 Features
- **Shorten URLs**: Generate a unique short code for any long URL.
- **Redirect to Original URL**: Use the short code to access the original link.
- **Caching with Redis**: Improve performance by caching URLs.
- **Analytics Tracking**: Monitor how many times a short URL has been accessed.
## 🏗 Tech Stack
- **Golang (Fiber)** - Fast and lightweight web framework
- **PostgreSQL** - Database for storing URLs
- **Redis** - Caching layer for fast lookups
- **Docker & Docker Compose** - Containerized deployment
## 📦 Installation & Setup
### 1️⃣ Clone the Repository
```sh
git clone https://github.com/telman03/go-url-service.git
cd go-url-service
```
### 2️⃣ Set Up Environment Variables
Create a `.env` file and configure the database & Redis:
```env
DATABASE_URL=postgres://user:password@localhost:5432/urlshortener
REDIS_ADDR=localhost:6379
```
### 3️⃣ Run Redis & PostgreSQL using Docker
```sh
docker-compose up -d redis postgres
```
### 4️⃣ Run the Service
```sh
go run main.go
```
## 📡 API Endpoints
### 1️⃣ Shorten a URL
```http
POST /api/shorten
```
**Request Body:**
```json
{
"url": "https://example.com"
}
```
**Response:**
```json
{
"short_url": "http://localhost:8080/abc123"
}
```
### 2️⃣ Redirect to Original URL
```http
GET /:shortcode
```
Example: `GET http://localhost:8080/abc123` → Redirects to `https://example.com`
### 3️⃣ Get URL Analytics
```http
GET /api/stats/:shortcode
```
**Response:**
```json
{
"shortcode": "abc123",
"clicks": 10
}
```
## 🛠️ Future Improvements
- 🔑 **User authentication** to manage links
- 📅 **URL expiration feature**
- 📊 **Admin dashboard** for analytics
- 🌍 **Custom domains support**
---
💡 **Contributions are welcome!** Feel free to open an issue or submit a pull request. 🚀