View Code? Open in Web Editor
NEW
URL shortener service in golang
License: MIT License
Dockerfile 4.44%
Go 71.15%
Shell 24.41%
go-urlshortener's Introduction
Overview of URL shortener service
- 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 |
Design decisions made while selecting libs:
-
logrus:
- 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
.
-
BBoltDB:
- 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.
-
httprouter:
- Lightweight high performance HTTP request router.
- Scales better.
- Best Performance. Check Benchmarks.
- Tools used: vegeta,ab
- Head over to
benchmark
directory in the repository for exploring the above two options with detailed guide on running them.
go-urlshortener's People
Contributors
Watchers