sami2020pro / espad-interview-task

Espad Pouysh Hamgan interview task | task completed

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spad interview task

spad interview task

spad interview task | task completed

Preview and Codes

spad interview task | tree the task 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

  1. Golang

  2. Golang libraries

  3. Redis

  4. Docker

How to create a unique identifier for URL

We paid attention to these
  1. Length

  2. Uniqueness

  3. 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

spad interview task | task completed | run-main-file

Run the Redis Server

spad interview task | task completed | run-redis-server

Create a short link

spad interview task | task completed | create-a-short-link

Generated short link in main

spad interview task | task completed | generated-link-main-file

Get detailed information for the short link

spad interview task | task completed | get-detailed-information-for-the-short-link

Enter and wait after get details

spad interview task | task completed | eneter-and-wait-after-get-details

Open the url in your Browser

spad interview task | task completed | open-the-url

Yoop !!! We redirected !!!

spad interview task | task completed | we-redirected

Docker

First

spad interview task | task completed | docker runed

Second

spad interview task | task completed | docker runed


('Sami Ghasemi)

About

Espad Pouysh Hamgan interview task | task completed

License:MIT License


Languages

Language:Go 96.8%Language:Dockerfile 3.2%