A simple URL shortener written in Go with both a console interface and a basic HTML web UI.
- Accepts a URL from the terminal or via web form.
- Automatically prepends
https://if missing. - Generates a random short identifier.
- Stores short → original URL mappings in memory.
- Exposes an
/api/shortenendpoint for web clients. - Redirects users from short URLs using
/gorelink/{id}. - Includes a basic HTML frontend with a logo.
- Open
index.htmlin your browser or host it via Go. - Enter a URL into the form.
- The shortened link will appear below the form.
- It uses
POST /api/shortento generate short URLs.
Request Body:
{
"url": "https://example.com"
}Response:
{
"shortURL": "http://localhost:8080/gorelink/XyZ123"
}CORS is enabled for local testing.
Currently uses in-memory map. Data will be lost when the program stops.
- Store links in a file or database.
- Add a web form for submitting URLs.
- Generate collision-free short IDs.
- Support expiration dates for short links.
This project includes unit tests for the HTTP handlers and storage logic.
To run tests, use:
go test ./...This will run all tests and show verbose output.
git clone https://github.com/DaniilPolskov/GoRelink.git
cd GoRelink
go run main.go