spad interview task
spad interview task
Preview and Codes
What is this project
This project is the task of Spad Company
TODOs
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
Does this project have any dependencies
Yes
What technologies did we use
We used these technologies
-
Golang
-
Golang libraries
-
Redis
-
Docker
How to create a unique identifier for URL
-
Length
-
Uniqueness
-
Search
What settings did we use for this project
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
How we worked with storage and Redis
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
How we handled the whole project
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
Why didn't we use Postman
We also had the ability to use Postman, but we didn't want it to get too crowded, so we used Redis for fun.
How to use this project
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
How to use the Docker
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
Contact
gmail
Example
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 !!!
Docker
First
Second
('Sami Ghasemi)