This will look at the exchange of currencies between EUR, USD and GBP:
- Get today's exchange value from currency1 to currency2.
- Get last week's exchange value from currency1 to currency2.
- Perform a naive comparison between the two to determine if today is a good time to exchange currency1 into currency2.
- Return the results -- single unit of curreny1 to curreny2 and the result of the naive comparison.
Type: GET
Query parameter: from
(required)
Valid values: {"EUR", "USD", "GBP"}
Query parameter: to
(required)
Valid values: {"EUR", "USD", "GBP"}
Status: 200
Body: {"dataDateTime":"2019-10-14T19:21:48.11587894+01:00","from":"EUR","shouldExchange":false,"singleUnit":1.1031,"to":"USD"}
Status: 400
Body: {"reason":"query params are invalid. EUR, USD and GBP are valid."}
Status: 500
Body: {"reason":""}
Request:
curl http://localhost:8080/v1/exchange?from=EUR\&to=USD -v
Response:
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /v1/exchange?from=EUR&to=USD HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Date: Mon, 14 Oct 2019 18:28:54 GMT
< Content-Length: 122
<
{"dataDateTime":"2019-10-14T19:28:54.823492804+01:00","from":"EUR","shouldExchange":false,"singleUnit":1.1031,"to":"USD"}
* Connection #0 to host localhost left intact
The following will build and place a binary file in the release/1.0.0/
directory:
./build.sh
Run with:
./release/1.0.0/exchange-1.0.0
To run all tests:
go test ./...
- 500 response with no reason in json response body.
- Requires logging to be implemented.
- Requires Cobra and Viper integration.
- More unit tests around failure cases, especially when a thread is getting data from network and other threads have to use stale data.
- Integration tests.
This was tested and working on:
- Lenovo ThinkPad X1 Carbon - Core i7-4600U - 8 GB Ram
- Ubuntu 18.04.3 LTS (binoic)