- Programming language: go
- Fast in-memory K/V store: BBoltDB
- HTTP router: httprouter
- Logging library: logrus
- https://github.com/pantrif/url-shortener
- https://github.com/pankajkhairnar/goShort
- https://github.com/xcoulon/go-url-shortener
- [POST] - http://localhost:8080/url : It accepts POST form data with parameter "url" and returns json response with short URL and the original URL.
- [GET] - http://localhost:8080/{SHORT_CODE}/ : If SHORT_CODE is valid and found in BBoltDB request will be redirected to original URL.
- All other non-existent endpoints will return
404
. - In case invalid json payload gets supplied, it'll return
422
.
Endpoint | Method | Payload | Response | Feature |
---|---|---|---|---|
/url | POST | {"url": "https://google.com"} | JSON | url validation, mandatory param |
/{short_code} | GET | 301 Redirection | redirects to original URL | |
/invalid_ep | GET | 404 | endpoint validation | |
/url | POST | {"uaarl": "https:///google.com"} | 422 | Invalid payload |
-
- Structural design of logrus makes user to think really hard about the important areas of the application where logging is absolutely required.
- Added benefits while doing log analysis with tools like
ELK stack
.
-
- For an app like URL shortener it made sense to use fast in-memory KV store instead of going for relational way.
- BBoltDB is the fork of BoltDB and both of them are widely used.
- Ease of use.
-
- Lightweight high performance HTTP request router.
- Scales better.
- Best Performance. Check Benchmarks.