GoShortURL is a powerful and flexible open-source URL shortener built with Go (Golang) and SQLite. It provides a simple and efficient way to create and manage short URLs, making it easy to share links and track their usage.
- Custom Short URLs: Create custom short URLs with ease.
- Metadata Scraping: Automatically fetches metadata (title, description, image) from the target URL.
- Analytics: Track the number of visits and last visit timestamp for each short URL.
- Pagination: Easily navigate through your list of short URLs with paginated results.
- Secure: Built with security in mind, ensuring reliable and safe URL shortening.
Ensure you have the following prerequisites installed before setting up and running the URL shortener:
- Go (Golang)
- SQLite
- Additional Go libraries (dependencies):
You can install these dependencies using the go get
command, for example:
go get -u github.com/PuerkitoBio/[email protected]
go get -u github.com/andybalholm/[email protected]
go get -u github.com/gorilla/[email protected]
go get -u github.com/mattn/[email protected]
go get -u golang.org/x/[email protected]
This ensures all required libraries are installed for the URL shortener project.
Feel free to adjust the wording or formatting based on your preferences.
Clone the repository:
git clone https://github.com/daniwebdev/go-short-url.git
cd go-short-url
Build and run the project:
GO_SHORT_KEY=your_api_key go run main.go
By default, the server will start on port 8080
. You can customize the port using the -port
flag.
To create a short URL, send a POST request to the /api
endpoint with a JSON payload:
curl -X POST http://localhost:8080/api -H "Content-Type: application/json" -H "X-API-Key: your_api_key" -d '{
"url": "https://example.com",
"custom_id": "custom_short_id",
}'
When creating a short URL, the metadata will be scraped from the provided URL, including title, description, and images, to enhance the information associated with the short URL. This ensures a richer preview when the short URL is accessed.
Feel free to customize the wording or provide additional details as needed.
To get a list of short URLs with pagination, send a GET request to the /api/{space}
endpoint:
curl http://localhost:8080/api/{space}?page=1&perPage=10 -H "Content-Type: application/json" -H "X-API-Key: your_api_key"
For more details on API endpoints, refer to the API Rest.
Contributions are welcome! Please check out our Contribution Guidelines for more details.
This project is licensed under the MIT License - see the LICENSE file for details.
- Gorilla Mux for the powerful router.
- goquery - A great library for working with HTML documents using jQuery-style syntax.
- cascadia - A CSS selector library for Go.
- go-sqlite3 - SQLite driver for Go, ensuring seamless database operations.
- golang.org/x/net - The Go networking libraries providing support for various protocols.