This code allows you to create a web server with the URL shortener function.
It's developed purely in Go, uses the official MongoDB drivers and Gorilla Mux for the routing.
Golang
MongoDB
Setting up your .env file (path: src/.env)
Database Name = "shorturl"
Collection Name = "shorturldata"
{ Url: 'string', Hash: 'hashed string' }
An example
{ Url: 'www.andreabacciu.com', Hash: 'bd443137fc0662f1e10f7f71ac948766' }
Use it in your favourite browser
Use this link: http://127.0.0.1:8080/insert/www.yourWebSiteURL.com
Using this function you will register a new URL in the database.
The synopsis of this function requires a parameter in the URL of the HTTP request, this parameter
is your URL to be shortened, this URL must not contain the prefix http:// or https:// or
quotation marks.
Use this link: http://127.0.0.1:8080/get/bd443137fc0662f1e10f7f71ac948766
Using this function you will be redirected to the requested page.
The synopsis of this function requires a parameter in the URL of the HTTP request, this parameter is an already known hash of a link
Use this link: http://127.0.0.1:8080/get_no_redirect/bd443137fc0662f1e10f7f71ac948766
Using this function you can go back to the name of the original link before the hash.
The synopsis of this function requires a parameter in the URL of the HTTP request, this parameter is an already known hash of a link
Compile it with GO
This is a toy project.
- .env file needs a real path. (Path src/lib/mongodbConnection.go Function: Init() )
- Currently, communications with the DB are not secure.
- The recorded URL must not contain the prefix http:// or https:// or quotation marks.
Feel free to open issue or pull request.
- Andrea Bacciu - github
This project is licensed under the MIT License - see the MIT license online for details