Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

ibigbug/short-url

Repository files navigation

short-url

Build Status Coverage Status

Simple short url service

Start the service

Docker

$ docker run -e PORT=80 -e ADDR=0.0.0.0 -p 8000:80 -e SITE_URL=YOUR_DOMAIN --rm -it ibigbug/short-url

Clean Virtual Machine

$ git clone https://github.com/ibigbug/short-url.git
$ cd short-url
$ sh ./scripts/bootstrap.sh
$ sh ./scripts/start.sh

Usage

$ curl -sX POST -H 'Content-Type: application/json' 'https://s.watfaq.com/shorten' -d '{"url":"http://a.very.long.url"}'
{"short": "https://s.watfaq.com/1"}
$ curl -sX GET -H 'Content-Type: application/json' 'https://s.watfaq.com/original' -d '{"short":"https://s.watfaq.com/1"}'
{"original": "http://a.very.long.url"}

TODO

  • auto redirect for original url
  • replace in-memory storage with Redis or other persistent stroage
  • implement querystring support

Pitfalls

  • slice in Golang will auto grow length
  • atomic inc should be used carefully
  • must wrap a new ResponseWriter to get the status code

About

Simple short url service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published