A simple URL shortener service written in Go.
- Shorten long URLs to compact links
- Redirect short links to original URLs
- RESTful API endpoints
- In-memory storage (can be extended)
- Go 1.18 or newer
git clone https://github.com/bash06/url-shortener.git
cd url-shortener
go build -o url-shortener
Start the server:
./url-shortener
By default, the server runs on localhost:8080
.
To run this service with docker rename the docker-compose.example
file into docker-compose.yml
and edit it to your liking. Then run docker-compose up
(you can add
-d
to detach the image from your terminal and run it in the background)
-
POST /shorten
Shorten a URL.
Request:
json { "url": "https://example.com" }
Response:
json { "short_url": "http://localhost:8080/abc123" }
-
GET /{short_code}
Redirects to the original URL.
You can configure the server port and other settings via environment variables or the config.toml
file. Every available config option is explained in the config.example.toml
file
MIT License