https://github.com/srivatsa17/url-shortener
A simple URL shortening service built with Go.
https://github.com/srivatsa17/url-shortener
base62-encoding golang postgresql snowflake
Last synced: about 3 hours ago
JSON representation
A simple URL shortening service built with Go.
- Host: GitHub
- URL: https://github.com/srivatsa17/url-shortener
- Owner: srivatsa17
- Created: 2026-04-13T17:28:12.000Z (about 2 months ago)
- Default Branch: master
- Last Pushed: 2026-04-16T18:03:12.000Z (about 2 months ago)
- Last Synced: 2026-04-16T19:12:03.671Z (about 2 months ago)
- Topics: base62-encoding, golang, postgresql, snowflake
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# URL Shortener
A simple URL shortening service built with Go. Convert long URLs into compact, shareable short codes with analytics tracking.
## ๐ Features
- **URL Shortening** - Convert long URLs into short, memorable codes
- **Click Analytics** - Track clicks for each shortened URL
- **URL Validation** - Protocol and format validation to prevent invalid URLs
- **Distributed ID Generation** - Snowflake-based unique ID generation for scalability
- **Environment Configuration** - Configurable via `.env` file
- **RESTful API** - Clean, intuitive API endpoints
- **Database Migrations** - Automatic schema setup on startup
## ๐ Prerequisites
- Go 1.16+
- PostgreSQL 12+
## ๐ ๏ธ Installation
1. **Clone the repository**
```bash
git clone https://github.com/srivatsa17/url-shortener.git
cd url-shortener
```
2. **Install dependencies**
```bash
go mod download
```
3. **Set up environment variables**
```bash
cp .env.example .env
# Edit .env with your database credentials
```
4. **Build the application**
```bash
make build
```
## ๐ Usage
### Start the server
```bash
make run
```
### API Endpoints
#### 1. Shorten URL
**POST** `/api/v1/shorten`
Request:
```json
{
"url": "https://example.com/very/long/url/path"
}
```
Response:
```json
{
"long_url": "https://example.com/very/long/url/path",
"short_url": "http://localhost:8080/r/abc123",
"created_at": "2026-04-16T10:30:45Z",
"click_count": 0
}
```
#### 2. Redirect to Original URL
**GET** `/api/v1/redirect?code=abc123`
- Redirects to the original long URL
- Increments click counter automatically
- Returns 404 if short code not found
#### 3. Health Check
**GET** `/health`
Response:
```json
{
"status": "healthy"
}
```
## ๐งช Testing
```bash
make test
```