Create a production ready web service which combines two existing web services. Fetch a random name from https://names.mcquay.me/api/v0 Fetch a random Chuck Norris joke from http://api.icndb.com/jokes/random?firstName=John&lastName=Doe&limitTo=nerdy Combine the results and return them to the user.
The project structure is taken from the set of common historical and emerging project layout patterns in the Go ecosystem. It may look ambiguous for such a small project butt it really worth it for bigger projects.
It took me approx. one hour to build the first working version and three more hours to refactor the code.
There are some unhandled errors in deferred calls.
To prevent over-engineering only one important function is tested. This is common for real-world programming. Also, note that tests run every time Docker image is being built.
$ git clone https://github.com/wildsurfer/task
Docker image is built from the scratch
image and is extremely small (~9mb) which is good for CI/CD pipelines.
$ cd task
$ docker build -f ./build/package/Dockerfile -t task .
$ docker run -it --rm -p 5000:5000 task .
$ docker run -it --rm -p 5000:5000 kek .
$ curl "http://localhost:5000"
$ ab -n 1000 -c 100 "http://localhost:5001/"