A simple fizz-buzz REST server with statistics.
Usage of fizzbuzz:
--port int Set the port on which the fizz-buzz server should listen (default 80)
--timeout int Set the maximum duration in seconds before timing out execution of fizz-buzz (default 30)
Basic health check, always returns 200 if the server is running.
This endpoint returns a JSON list of strings with numbers from 1 to limit, where:
all multiples of int1 are replaced by str1, all multiples of int2 are replaced
by str2, all multiples of int1 and int2 are replaced by str1str2.
It accepts the following query parameters:
int1- required, non-zero integerint2- required, non-zero integerlimit- required, non-zero positive integerstr1- a stringstr2- a string
Example (200 OK)
/api/v1/fizz-buzz?int1=2&int2=3&limit=10&str1=foo&str2=bar
["1","foo","bar","foo","5","foobar","7","foo","bar","foo"]Example (400 Bad Request)
/api/v1/fizz-buzz?int1=2&int2=0&limit=10&str1=foo&str2=bar
{"message":"zero int1 and/or int2"}Example (503 Service Unavailable)
{"message":"context deadline exceeded"}This endpoint returns a JSON object with the parameters of the most frequent request and the number of occurrences of this request.
Example (200 OK)
/api/v1/stats
{"count":10,"int1":"2","int2":"3","limit":"10","str1":"foo","str2":"bar"}📣 Current implementation of this endpoint relies on an in memory data source. In other words, the statistics are not persisted between runs nor are they relevant in a distributed environment.
However, one may provide its own data source implementation by implementing the
stats.Statitistics interface. Suitable data sources could be either No-SQL or SQL.
For the latter, the implementer will have to make sure the requests' parameters do not
lead to SQL injection (e.g., str1 equals DROP TABLE foo;).
Requirements
- Go >= 1.16
- golangci-lint >= 1.39
- A linux-like terminal (ideally)
Makefile commands
make fmt- Shortcut forgo fmtandgo mod tidymake lint- Runs lintersmake tests- Runs testsmake todos- Shows TODOsmake godoc- Runs a local webserver for godocmake run- Runs the application (PORTandTIMEOUTare available as variables, i.e,make run PORT=80 TIMEOUT=30)make build- Builds the application (VERSIONis available as variable, i.e,make build VERSION=foo)