Skip to content

yusianglin11010/url-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url shortener

An url shortener server realized by golang and redis. Followed the guide from Let's build a URL shortener in Go - Part I. Besides, I added extra feature for deployment, a docker file and docker-compose for quick start in any environment.

Built with

Docker Golang Redis

Quick Start

  1. build go server's image
docker build -t go-url-server .
  1. run service on
docker-compose up
  1. shorten your url
curl -X POST {your-host}/url -d '{"long_url": "https:google.com"}'
# expected output
# {your-host}/Lhr4BWAi
  1. check if server redirect {your-host}/Lhr4BWAi to https://google.com

How It Works

Convert original URL to another shorter identical string

  • Hash Original URL With Sha256
  • Encode the Hashed Result With Base58
    • This server encoded URL with base58 for improving user experience. It avoided tje usage of the following confusing characters: "O", "0", "I", "l", "+" and "/".

Redirect the generated shorter url to the original one

  • When user hit the host IP with shortened url, server would lookup the original url in redis and redirect the user to original url.

Roadmap

  • Add go server Dockerfile
  • Add docker-compose
  • Check if generated duplicated URL