A non-persistent fast URL-shortening service in Golang using valaya/fasthttp and patrickmn/go-cache.
- Links only persist as long as needed
- Speed is good
- You don't like databases
To shorten https://google.com to hostname/google
for 60 seconds, make a request to hostname/put
{
"url": "https://google.com",
"key": "google",
"seconds": 60
}
Prohibited keys:
put
ok
To be redirected to https://google.com after PUT-ing the above, make a request to hostname/google
See config.json
Ran locally on a mid-2015 15" MBP
BenchmarkPutLink-8 500000 2912 ns/op
BenchmarkGetLink-8 2000000 848 ns/op
BenchmarkCacheShortenerPut-8 2000000 727 ns/op
BenchmarkCacheShortenerGet-8 10000000 230 ns/op
Clone the repo: go get github.com/davidlu1997/fast-shortener
- Run tests:
make test
- Run benchmarks:
make benchmark
- Run server:
make run
- Check health:
curl http://localhost:8069/ok
- Lint actionable:
make lint
- Lint all:
make lint-all