A simple URL shortener built with Go and MongoDB.
- Go (v1.16 or higher)
- MongoDB
- Clone the repository:
git clone https://github.com/cchhaarroonn/LilShorty.git
- Change to the project directory:
cd LilShorty
- Initialize project and get dependencies:
go mod init <charon/lilshorty>
go get github.com/gin-gonic/gin
go get go.mongodb.org/mongo-driver/mongo
- Set up MongoDB by creating a database and a collection. Update the MongoDB connection URL in the code:
client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://<username>:<password>@<host>:<port>")) <line 22>
- Run the application:
go run main.go
- The server will start running on locahost:42069 by default change it on line 127
Send a POST request to /createShort/:url to shorten a URL. Replace :url with the actual URL you want to shorten.
POST /createShort/http://example.com
{
"status": "URL shortened, key is: <generated-key>"
}
GET /short/<generated-key>
{
"status": "<original-url>"
}
Contributions are welcome! If you find any issues or want to add new features, please open an issue or submit a pull request.
As always there is a note lmao ... I might make website for this like basic html, css, js but it really depends if I want to burn my brain at some point until then just enjoy using this simple thingy it is not much but is quite good