Skip to content

About

Urlbit – Minimal URL Shortener built with Go + Gin πŸ”₯πŸ”₯πŸ”₯

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”— Go URL Shortener – Fast & Simple

Go Gin PostgreSQL Clerk License

✨ A backend URL Shortener built using Golang + Gin + PostgreSQL, with Clerk authentication, rate limiting and clean routes.


⚑ Key Features

  • πŸ”— URL Shortening
  • πŸ” Redirect Handler
  • πŸ” Clerk Auth Middleware
  • πŸ“¦ PostgreSQL Storage
  • ⚑ Gin high-performance router
  • 🧩 Signup webhook
  • 🧱 Rate Limiting middleware
  • πŸ”§ Modular structure

πŸ“¦ Tech Stack

  • 🦦 Golang (1.22+) – Fast, compiled, highly performant backend language
  • 🌿 Gin Framework – Lightweight, minimal & extremely fast HTTP router
  • πŸ—„οΈ PostgreSQL – Relational storage for persistent URL and user data
  • πŸ›‘οΈ Clerk Authentication – Secure user auth + webhooks

πŸ”— API Endpoints

Below are all available endpoints explained briefly πŸ‘‡

  • GET /health-check (Public)

    Checks if the server is healthy and running properly.


  • POST /shorten (Private)

    Creates a short URL for the authenticated user.
    Requires Clerk authentication & rate limiting.


  • GET /:code (Public)

    Redirects to the original long URL based on the short code.
    Returns 404 if the URL does not exist.


  • GET /stats (Private)

    Returns paginated list of URLs owned by the authenticated user.
    Useful for analytics / dashboard views.


  • DELETE /:code (Private)

    Deletes a specific URL owned by the authenticated user.


  • POST /webhook/signup (Public)

    Clerk signup webhook.
    Triggers when a new user registers.


πŸ› οΈ Getting Started

1. Clone the repo

git clone https://github.com/LokeshXs/urlbit_url-shortener.git
cd urlbit_url-shortener

2. Install dependencies

go mod tidy

3. Setup Environment variables in .env file from .env.example file

cp .env.example .env

Then open .env and fill the values:

POSTGRES_URL=<your-postgres-url>
CLERK_SECRET_KEY=<your-clerk-secret-key>

6. Run the development server

go run main.go

If everything is setup correctly, you should now see the service running locally πŸŽ‰

Database connection or table initialization failures are logged without stopping the HTTP server. /health-check remains available and reports server liveness. Database-dependent endpoints return HTTP 500 with {"message":"Internal server error"} while PostgreSQL is unavailable. Each request retries the database check and any unfinished table initialization, so service resumes when PostgreSQL recovers. Missing or invalid POSTGRES_URL configuration requires correcting the environment and restarting the app.


✨ Why I built this

Because almost every product needs a clean and reliable short-link systemβ€”and building this from scratch gives maximum control & full ownership instead of depending on third-party platforms πŸ‘¨β€πŸ’»


πŸ§‘β€πŸ’» Author

Lokesh Singh
πŸ”— Portfolio β€” https://lokesh-singh.vercel.app/

About

Urlbit – Minimal URL Shortener built with Go + Gin πŸ”₯πŸ”₯πŸ”₯

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages