go-url-shortener allows you to create short URLs to redirect to any fully-qualified URL, and retrieve the referrals by simply querying the shortened URL.
- Shortens any URL to a 12-characdter re-direct.
- Retrieves the fully-qualified URL for any short URL.
- Accessible via RESTful interface or with provided CLI tool.
For the API:
cd ./cmd && go build -o <name> && ./<name>
For the CLI:
cd .cmd/cli && go build -o <name> && ./<name> <command> <params>
Accessed via:
POST /shorten/
{
"url": "https://www.lush.com/uk/en/p/good-karma-everybody-needs-some-shower-gel",
}
{
"longURL": "https://www.lush.com/uk/en/p/good-karma-everybody-needs-some-shower-gel",
"shortURL": "https://df.dv/9UhhRFxVDElPV06C",
}
Accessed via:
GET /
GET https://df.dv/9UhhRFxVDElPV06C
{
"longURL": "https://www.lush.com/uk/en/p/good-karma-everybody-needs-some-shower-gel",
"shortURL": "https://df.dv/9UhhRFxVDElPV06C",
}
The CLI tool supports both shortening and longening of URLs, accessible by running it in one of the two following ways.
./cli shorten -shorten-URL=https://www.lush.com/uk/en/p/good-karma-everybody-needs-some-shower-gel
https://df.dv/9UhhRFxVDElPV06C
./cli longen -longen-URL=kSDOejD9yPsuKRuO
https://www.lush.com/uk/en/p/good-karma-everybody-needs-some-shower-gel
handler name | ns/op | bytes/op | allocs/op |
---|---|---|---|
shortenURLHandler | 259277 | 18716 | 136 |
retrieveURLHandler | 289681 | 18245 | 131 |
app name | ns/op | bytes/op | allocs/op |
---|---|---|---|
stripURL | 2854 | 105 | 0 |
urlShortener | 705.7 | 16 | 1 |
validateShortURL | 226.2 | 0 | 0 |
db operation | ns/op | bytes/op | allocs/op |
---|---|---|---|
Store | 1786 | 230 | 2 |
Retrieve | 1397 | 224 | 3 |