ShortNGo is a URL shortening service built with Go and powered by HTMX. It uses BadgerDB as the underlying storage mechanism to store and retrieve shortened URLs.
- Shorten long URLs.
- Redirect to the original URL using the shortened URL.
- Uses a hash function to generate unique shortened URLs.
- In-memory database using BadgerDB for fast performance.
- Go 1.16 or higher
- Internet connection to fetch dependencies
- Clone the repository:
git clone https://github.com/yourusername/shortngo.git
cd shortngo
- Install dependencies:
go mod tidy
- Run the application:
go run .
- Open your web browser and go to
http://localhost:8080
.
-
POST /process
This endpoint accepts a URL via a form and generates a shortened version.
-
GET /go/{hash}
This endpoint redirects to the original URL associated with the given hash.
Example:
curl http://localhost:8080/go/c19fcdc5
main.go
- Entry point of the application, handles HTTP routing and request processing.database/*
- Contains the database implementations and factory.
To run the tests, use the following command:
go test ./...
This will execute the tests defined in database/badgerim_test.go
to ensure the database implementation is working as expected.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE
file for more details.
- BadgerDB for the in-memory database.
- HTMX for handling AJAX requests in a simpler way.
- Murmur3 for the hashing function.
Feel free to customize this README to better fit your project and personal style.