Technical test for Leboncoin.
Web API written in Go.
Your goal is to implement a web server that will expose a REST API endpoint that:
- Accepts five parameters: three integers int1, int2 and limit, and two strings str1 and str2.
- Returns a 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.
The server needs to be:
- Ready for production
- Easy to maintain by other developers
Bonus: add a statistics endpoint allowing users to know what the most frequent request has been. This endpoint should:
- Accept no parameter
- Return the parameters corresponding to the most used request, as well as the number of hits for this request
Using go cli:
$ go run .
⇨ http server started on [::]:8080Using Docker:
$ docker build -t leboncoin .
$ docker run -p 8080:8080 leboncoinThis will expose an HTTP web server on the 8080 port.
You can access it with this URL: http://127.0.0.1:8080/
Returns a 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
int1integerint2integerlimitintegerstr1stringstr2string
$ export INT1=3 INT2=5 LIMIT=10 STR1=fizz STR2=buzz
$ curl "http://127.0.0.1:8080/?int1=$INT1&int2=$INT2&limit=$LIMIT&str1=$STR1&str2=$STR2"
["1","2","fizz","4","buzz","fizz","7","8","fizz","buzz"]Return the parameters corresponding to the most used request, as well as the number of hits for this request.
Member key is constructed as the following: int1_int2_limit_str1_str2
$ curl "http://127.0.0.1:8080/metrics"
[
{
"Score": 1,
"Member": "3_5_30_fizz_buzz"
},
{
"Score": 2,
"Member": "3_5_10_fizz_buzz"
},
{
"Score": 3,
"Member": "32_5_10_fizz_buzz"
},
{
"Score": 11,
"Member": "32_531_10_fizz_buzz"
}
]A CI is running on every push thanks to Github Actions. This CI contains a lint and a build workflows.
That follows the best Go lint practices and test the build on every code changes.
You can specify optional environment variables to change default server variables:
PORTThe web endpoint listening port (default:8080)HOSTThe web endpoint listening address (default:0.0.0.0)REDIS_URLThe redis URL to connect to (default: inmemory redis instance)
Made by Antoine Ordonez.
Website: https://shellbear.me