A golang implementation of URL shortener like Bitly
✅ Users can create custom shorten URL
✅ Rate limiter to restrict users to exploit the API
✅ Containerized the whole application using Docker and Docker-compose for easy set-up
✅ Suitable checks for non-redundancy in URL creation
-
Clone the repository using
git clone <repo_url>
-
Go to the project directory using
cd golang-url-shortener
-
Run
go mod tidy
or you can manually install all the golang dependencies usinggo get <dep_name>
command. -
Install docker and docker-compose on windows, follow these instructions for easy setup.
-
Create a
.env
file in/api/
folder similar to.env.example
file. -
Run
docker-compose up -d
to spin the docker containers for Go-Fiber server and Redis database at portslocalhost:3000
andlocalhost:6379
respectively. -
You can test the API using postman or VSCode's thunder client using following api call:
- POST request at
localhost:3000/api/v1
with body:
{ "url" : "URL_TO_BE_SHORTEN", "custom" : "UNIQUE_CUSTOM_URL_ID" }
which will respond you with a response format:
{ "url": "URL_TO_BE_SHORTEN", "short": "SHORTEN_URL", "expiry": "Cache expiry {set to 30 mins}", "rate_limit": "No of times the API have been called", "rate_limit_reset": "After how much time the rate limit will reset (in hours)", }
- GET request at
localhost:3000/:URL_TO_BE_SHORTEN
will redirect to the original URL.
- POST request at