shorturl

URL shortener

This is an example of how to create a URL shortener using:

The code NOT autogenerated is included in the following packages/files:

The code autogenerated is NOT covered by tests, everything else has a coverage of ~ 80%

image

Development:

To add new Api modify swagger-ui/swagger.yml and run:

$swagger generate server -f ./swagger-ui/swagger.yml --exclude-main

Be aware, if you modify any autogenerated file it will be overwritten running such command.

Run test running: $go test ./...

Usage

To execute the server clone the repo, cd into it and run:

$go run ./cmd/url-shortener-server/main.go --port 35307

Navigate to localhost:35307/swagger-ui to visualise the UI and test APIs with a frontend Navigate to localhost:35307/metrics to check metrics, in particular url_redirected keeps track of redirection since last execution

There are three methods under /api:

Shortened URLs will be like short-abcdefghil and can be used as follows localhost:35307/short-abcdefghil

If you try to navigate to a shortened url that does not exist (es: localhost:35307/short-notExisting) you will be redirected to http://www.notfound.com