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

 
 
 

Contributors

Languages