https://github.com/andreabac3/shortener-url-golang
Shortener URL in pure Golang and MongoDB
https://github.com/andreabac3/shortener-url-golang
andreabac3 goland golang gorillamux md5 mongo mongodb mongodb-driver mux shorten-urls shortnerurl shorturl url webserver
Last synced: about 1 month ago
JSON representation
Shortener URL in pure Golang and MongoDB
- Host: GitHub
- URL: https://github.com/andreabac3/shortener-url-golang
- Owner: andreabac3
- Created: 2019-08-03T15:50:26.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-17T21:07:26.000Z (about 4 years ago)
- Last Synced: 2025-05-15T12:09:57.317Z (about 1 year ago)
- Topics: andreabac3, goland, golang, gorillamux, md5, mongo, mongodb, mongodb-driver, mux, shorten-urls, shortnerurl, shorturl, url, webserver
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Shortener URL in pure Golang and MongoDB
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.
## Getting Started
## Prerequisites
```
Golang
MongoDB
Setting up your .env file (path: src/.env)
```
### MongoDB
Database Name = "shorturl"
Collection Name = "shorturldata"
```
{ Url: 'string', Hash: 'hashed string' }
An example
{ Url: 'www.andreabacciu.com', Hash: 'bd443137fc0662f1e10f7f71ac948766' }
```
## Test
Use it in your favourite browser
#### Record URL
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.
#### Redirect from shortner URL
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
#### Convert from hashed URL to un-hashed URL
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
## Program execution
Compile it with GO
# Known Issues
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.
## Contributing
Feel free to open issue or pull request.
# Authors
* **Andrea Bacciu** - [github](https://github.com/andreabac3)
## License
[](https://github.com/andreasonny83/unique-names-generator/blob/master/LICENSE)
This project is licensed under the MIT License - see the MIT license online for details