This project is a simple URL shortener written in Go, allowing users to shorten long URLs and share them via the generated short link.
The program creates a SQLite database in the current user's directory to store the shortened URLs.
After creating the SQLite database, a web server is set up using the net/http
package. This server hosts the various endpoints required for the functionality of the URL shortener.
- Shortening long URLs into custom short links.
- Tracking clicks for each short link.
- Customizing the port of the web server via a command-line parameter.
/api/create?url=yourwebsite
: Creates a short URL for the specified long URL./api/delete?short=yourshort
: Deletes the short URL corresponding to the given short code./api/all
: Returns all short URLs in JSON format./api/clicks?short=yourshort
: Returns the click count of the specified short URL./short
: Redirects to the long url.
You can clone the source code using Git:
git clone https://github.com/LionTV/url-shortener.git
Make sure you have the latest go version. Then, navigate to the project directory and run the following command to install dependencies:
cd url-shortener
go mod tidy
go build
Run the compiled program and specify the desired port of the web server as a command-line parameter. By default, port 80 will be used.
./url-shortener.exe -port=80
Open your web browser and navigate to http://localhost:<port>
, where <port>
is the port you specified (default is 8080). You will then see the user interface of the URL shortener, where you can enter long URLs to shorten them.
Contributions are always welcome! If you find a bug or want to add a feature, feel free to open a pull request.