Simple short url service
$ docker run -e PORT=80 -e ADDR=0.0.0.0 -p 8000:80 -e SITE_URL=YOUR_DOMAIN --rm -it ibigbug/short-url
$ git clone https://github.com/ibigbug/short-url.git
$ cd short-url
$ sh ./scripts/bootstrap.sh
$ sh ./scripts/start.sh
$ 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"}
- auto redirect for original url
- replace in-memory storage with Redis or other persistent stroage
- implement querystring support
- slice in Golang will auto grow length
- atomic inc should be used carefully
- must wrap a new ResponseWriter to get the status code