go-short-url
is a URL shortener service written in Go (Golang) with an HTMX frontend. This project makes it easy to shorten URLs for easier sharing and management, while also offering retrieval of original URLs based on their shortened versions. It runs on a lightweight HTTP server on port 8080 with a simple frontend.
- GET and POST methods for shortening and retrieving URLs
- Customizable hash size for the generated URLs
- Basic error handling for unsupported methods and invalid URLs
- Go 1.16 or above
To get started, clone the repository and navigate into its directory:
git clone https://github.com/yourusername/go-short-url.git
cd go-short-url
docker-compose up -d
Go to: http://127.0.0.1:8080
To shorten a URL, make a POST request to the root /
:
curl -d "url=http://example.com" -X POST http://127.0.0.1:8080/
To retrieve the original URL, navigate to the shortened URL in your browser or use a GET request. For example:
curl http://127.0.0.1:8080/{hash}
- "Method not allowed": Unsupported HTTP method
- "Invalid URL format": URL doesn't meet the required format
- "URL not found": The hash doesn't correspond to any stored URL
- "Something went wrong": Internal server error
Contributions are welcome! Feel free to open an issue or submit a pull request.
This project is under the MIT License. See LICENSE.md for details.