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.
- 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
URL-short/
βββ main.go # Main service program
βββ README.md # Project documentation
-
Start the service
go run main.go
-
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" } ``` -
Access the short code for redirection
Open in browser or use curl:
http://localhost:8080/abc123You will be redirected to the original long URL.
- Uses Go standard library
net/httpfor web service - Thread-safe in-memory storage (
sync.RWMutex) - Random short code generation algorithm, supports high concurrency
- Clean code structure with detailed comments
- 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
Feel free to submit Issues or Pull Requests to improve features or optimize the code.
MIT License
Made with β€οΈ by namezzy