A simple, self-hosted URL shortener built with Go and SQLite. Create short, easy-to-share links with a clean web interface, API, and CLI support.
- Simple Web Interface: Easily create, manage, and track shortened URLs
- Custom Short Codes: Create memorable, branded short links
- QR Code Generation: Generate QR codes for your shortened URLs
- Click Tracking: Track how many times your shortened URLs have been clicked
- API Support: Programmatically create and manage shortened URLs
- CLI Support: Command-line interface for URL shortening
- Self-Hosted: All your data stays on your server with SQLite
- Single Binary: Easy to deploy with no external dependencies
Download the latest release from the releases page.
git clone https://github.com/mstgnz/self-hosted-url-shortener.git
cd self-hosted-url-shortener
go build -o url-shortener ./cmd
Start the server:
./url-shortener --port 8080 --base-url "https://your-domain.com"
Then open your browser and navigate to http://localhost:8080
(or your custom domain).
The URL shortener provides a RESTful API:
curl -X POST http://localhost:8080/api/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/very/long/url", "custom_code": "my-link"}'
curl -X GET http://localhost:8080/api/urls
curl -X GET http://localhost:8080/api/url/my-link
curl -X DELETE http://localhost:8080/api/url/my-link
The URL shortener also provides a command-line interface:
./url-shortener --cli shorten https://example.com/very/long/url
With a custom code:
./url-shortener --cli shorten https://example.com/very/long/url --code my-link
./url-shortener --cli list
./url-shortener --cli get my-link
./url-shortener --cli qr my-link --output qr.png
./url-shortener --cli delete my-link
The URL shortener can be configured using command-line flags:
--port
: HTTP server port (default: 8080)--db
: SQLite database path (default: data.db)--base-url
: Base URL for shortened URLs (default: http://localhost:8080)--templates
: Templates directory (default: templates)--cli
: Run in CLI mode
- Go 1.18 or higher
- SQLite
- Clone the repository:
git clone https://github.com/mstgnz/self-hosted-url-shortener.git
cd self-hosted-url-shortener
- Install dependencies:
go mod download
- Run the application:
go run ./cmd
This project is licensed under the MIT License - see the LICENSE file for details.