mkdir -p $GOPATH/src/github.com/rammiah
cd $GOPATH/src/github.com/rammiah
git clone https://github.com/rammiah/shorturl
cd shorturl
go build
./shorturl
POST <server:port>/generate
data body is url to shorten
return {"surl": "short url", "url": "url you input"}
GET surl
will be redirected to url
➜ shorturl git:(master) ✗ curl -X POST rammiah.org:8080/generate -d "https://www.baidu.com"
{"surl":"http://rammiah.org:8080/to/fiCEerXQ","url":"https://www.baidu.com"}%
➜ shorturl git:(master) ✗ curl http://rammiah.org:8080/to/fiCEerXQ
<a href="https://www.baidu.com">Moved Permanently</a>.
➜ shorturl git:(master) ✗
url must be starts with http://
or https://
. Or it will be parsed as a link belong to your domain
Example:
url: baidu.com
server: rammiah.org
redirect to: rammiah.org/to/baidu.com