The original fizz-buzz consists in writing all numbers from 1 to 100, and replacing:
- all multiples of
3byfizz, - all multiples of
5bybuzz, - and all multiples of
15byfizzbuzz.
The output would look like this:
1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,fizz,...
Expose a REST API endpoint /fizz-buzz that accepts five parameters : two strings (say, string1 and string2), and three integers (say, int1, int2 and limit), and returns a JSON
It must return a list of strings with numbers from 1 to limit, where:
- all multiples of int1 are replaced by string1,
- all multiples of int2 are replaced by string2,
- all multiples of int1 and int2 are replaced by string1string2
Expose a REST API endpoint /stats that retrieves all statistics about the calls
I have used gin-gonic framework to handle the web server part, and build/test my endpoints. This part is located in the pkg/server folder.
The core of the game rules are located in the pkg/business folder.
The statistics storage is a SQlite database and the service client is located in pkg/storage folder.
For both following cases, you can test the endpoint:
The project has been set up on Windows, following commands might change on other OS
Launch all tests and check coverage:
go test -race -covermode atomic -coverprofile .\coverage.txt ./...
Build:
go build -o fizzBuzzApp .\cmd\api\main.go
Run:
go run .\cmd\api\main.go
Install Docker Engine
The image is build in the Gitlab CI according to the .gitlab-ci.yml file and the Dockerfile. It it then pushed to the registry. The docker-compose.yaml file pulls it from the registry and runs a container within Docker Engine.
- To update the image:
docker-compose pull
- To run the image
docker-compose up -d