spad interview task
This project is the task of Spad Company
We need create and write:
1) Generate a unque alias for the provided address
2) The service should redirect users to original URLs when they access a short link
3) The short link have a lifetime
4) The service should have a visits count
5) Docker image
6) Use camelCase
7) Clean code
Yes
We used these technologies
-
Golang
-
Golang libraries
-
Redis
-
Docker
-
Length
-
Uniqueness
-
Search
We put all the Redis settings in one Json file
And you can find all the settings in the configuration.json
file
And You can change your settings in the configuration.json
file
We wrote a Golang code to do our job with Redis
And you can find this code in the storage.go
file in the storage directory
We divided the tasks and wrote a special code for each task and wanted each section to do its job efficiently.
Base:
base62.go
Config:
configuration.go
Handler:
handler.go
Storage:
storage.go
Docker:
Dockerfile
Main:
main.go
We also had the ability to use Postman, but we didn't want it to get too crowded, so we used Redis for fun.
Get the modules and dependencies
go mod download
Run service
go run main.go
Create a short link
curl -L -X POST 'localhost:8080/encode' -H 'Content-Type: application/json' --data-raw '{
"url": "WRITE-YOUR-URL-IN-HERE",
"expires": "WRITE-YOUR-EXPIRE-TIME-IN-HERE"
}'
we will get a response like:
{
"success": true,
"shortUrl": "http://localhost:8080/THE-SHORT-URL"
}
Any short url can be included in the THE-SHORT-URL
Get detailed information for the short link
curl -L -X GET 'http://localhost:8080/THE-SHORT-URL'
Open the browser and follow the your short link
http://localhost:8080/THE-SHORT-URL
Go to the task file and we will run in terminal command to build Docker image
docker build . -t task
Run the Docker image
docker run -p 8080:8080 task
gmail
Run main file
Run the Redis Server
Create a short link
Generated short link in main
Get detailed information for the short link
Enter and wait after get details
Open the url in your Browser
Yoop !!! We redirected !!!
First
Second
('Sami Ghasemi)