Skip to content

namezzy/URL-short

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Go URL Shortener Service

An elegant and simple URL shortener written in Go


🌟 Overview

This project is a fast and efficient URL shortener service built with Go. Users can submit long URLs, and the system generates a short code. Accessing the short code will redirect to the original URL. Perfect for learning, demos, and small applications.

✨ Features

  • Randomly generates 6-character short codes to avoid collisions
  • In-memory storage for fast mapping between short codes and long URLs
  • Simple and easy-to-use API endpoints
  • Well-commented code, easy to extend

πŸ“¦ Project Structure

URL-short/
β”œβ”€β”€ main.go      # Main service program
└── README.md    # Project documentation

πŸš€ Quick Start

  1. Start the service

    go run main.go
  2. Shorten your long URL

    curl -X POST -H "Content-Type: application/json" \
        -d '{"url":"https://www.example.com"}' \
        http://localhost:8080/shorten
      Example response:
      ```json
      {
          "short_url": "/abc123",
          "link": "http://localhost:8080/abc123"
      }
      ```
    
  3. Access the short code for redirection

    Open in browser or use curl:

    http://localhost:8080/abc123
    

    You will be redirected to the original long URL.

πŸ›  Technical Details

  • Uses Go standard library net/http for web service
  • Thread-safe in-memory storage (sync.RWMutex)
  • Random short code generation algorithm, supports high concurrency
  • Clean code structure with detailed comments

⚠️ Notes

  • This version uses in-memory storage only; data will be lost after service restart
  • Suitable for learning and small projects; for production, consider using a database

🀝 Contributing

Feel free to submit Issues or Pull Requests to improve features or optimize the code.

πŸ“„ License

MIT License


Made with ❀️ by namezzy

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages