|
| 1 | +# GoShortURL- Open Source URL Shortener |
| 2 | + |
| 3 | +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. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Custom Short URLs**: Create custom short URLs with ease. |
| 8 | +- **Metadata Scraping**: Automatically fetches metadata (title, description, image) from the target URL. |
| 9 | +- **Analytics**: Track the number of visits and last visit timestamp for each short URL. |
| 10 | +- **Pagination**: Easily navigate through your list of short URLs with paginated results. |
| 11 | +- **Secure**: Built with security in mind, ensuring reliable and safe URL shortening. |
| 12 | + |
| 13 | +## Getting Started |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | + |
| 17 | +Ensure you have the following prerequisites installed before setting up and running the URL shortener: |
| 18 | + |
| 19 | +- Go (Golang) |
| 20 | +- SQLite |
| 21 | +- Additional Go libraries (dependencies): |
| 22 | + - [github.com/PuerkitoBio/goquery v1.8.1](https://pkg.go.dev/github.com/PuerkitoBio/goquery) |
| 23 | + - [github.com/andybalholm/cascadia v1.3.2](https://pkg.go.dev/github.com/andybalholm/cascadia) |
| 24 | + - [github.com/gorilla/mux v1.8.1](https://pkg.go.dev/github.com/gorilla/mux) |
| 25 | + - [github.com/mattn/go-sqlite3 v1.14.19](https://pkg.go.dev/github.com/mattn/go-sqlite3) |
| 26 | + - [golang.org/x/net v0.19.0](https://pkg.go.dev/golang.org/x/net) |
| 27 | + |
| 28 | +You can install these dependencies using the `go get` command, for example: |
| 29 | + |
| 30 | +```bash |
| 31 | +go get -u github.com/PuerkitoBio/goquery@v1.8.1 |
| 32 | +go get -u github.com/andybalholm/cascadia@v1.3.2 |
| 33 | +go get -u github.com/gorilla/mux@v1.8.1 |
| 34 | +go get -u github.com/mattn/go-sqlite3@v1.14.19 |
| 35 | +go get -u golang.org/x/net@v0.19.0 |
| 36 | +``` |
| 37 | + |
| 38 | +This ensures all required libraries are installed for the URL shortener project. |
| 39 | + |
| 40 | +Feel free to adjust the wording or formatting based on your preferences. |
| 41 | + |
| 42 | +### Installation |
| 43 | + |
| 44 | +Clone the repository: |
| 45 | + |
| 46 | +```bash |
| 47 | +git clone https://github.com/daniwebdev/go-short-url.git |
| 48 | +cd go-short-url |
| 49 | +``` |
| 50 | + |
| 51 | +Build and run the project: |
| 52 | + |
| 53 | +```bash |
| 54 | +GO_SHORT_KEY=your_api_key go run main.go |
| 55 | +``` |
| 56 | + |
| 57 | +By default, the server will start on port `8080`. You can customize the port using the `-port` flag. |
| 58 | + |
| 59 | +### Usage |
| 60 | + |
| 61 | +#### Creating a Short URL |
| 62 | + |
| 63 | +To create a short URL, send a POST request to the `/api` endpoint with a JSON payload: |
| 64 | + |
| 65 | +```bash |
| 66 | +curl -X POST http://localhost:8080/api -H "Content-Type: application/json" -H "X-API-Key: your_api_key" -d '{ |
| 67 | + "url": "https://example.com", |
| 68 | + "custom_id": "custom_short_id", |
| 69 | +}' |
| 70 | +``` |
| 71 | + |
| 72 | +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. |
| 73 | + |
| 74 | +Feel free to customize the wording or provide additional details as needed. |
| 75 | + |
| 76 | +#### Retrieving Short URLs |
| 77 | + |
| 78 | +To get a list of short URLs with pagination, send a GET request to the `/api/{space}` endpoint: |
| 79 | + |
| 80 | +```bash |
| 81 | +curl http://localhost:8080/api/{space}?page=1&perPage=10 -H "Content-Type: application/json" -H "X-API-Key: your_api_key" |
| 82 | +``` |
| 83 | + |
| 84 | +For more details on API endpoints, refer to the [API Rest](api.rest). |
| 85 | + |
| 86 | +## Contributing |
| 87 | + |
| 88 | +Contributions are welcome! Please check out our [Contribution Guidelines](CONTRIBUTING.md) for more details. |
| 89 | + |
| 90 | +## License |
| 91 | + |
| 92 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 93 | + |
| 94 | +## Acknowledgments |
| 95 | + |
| 96 | +- [Gorilla Mux](https://github.com/gorilla/mux) for the powerful router. |
| 97 | +- [goquery](https://github.com/PuerkitoBio/goquery) - A great library for working with HTML documents using jQuery-style syntax. |
| 98 | +- [cascadia](https://github.com/andybalholm/cascadia) - A CSS selector library for Go. |
| 99 | +- [go-sqlite3](https://github.com/mattn/go-sqlite3) - SQLite driver for Go, ensuring seamless database operations. |
| 100 | +- [golang.org/x/net](https://pkg.go.dev/golang.org/x/net) - The Go networking libraries providing support for various protocols. |
0 commit comments