Topics covered in this challenge:
- Webserver http
- context
- database
- file
Prerequisites
- Go
- SQLite3
The requirements to meet this challenge are:
- The
server.go
must consume the API containing the exchange of Dollar and Real at the address:https://economia.awesomeapi.com.br/json/last/USD-BRL
and then it must return the result in JSON format to the client . - Using the
context
package,server.go
must register each received quote in the SQLite database, and the maximum timeout to call the dollar quote API must be200ms
and the maximum timeout to be able to persist the data in the database should be10ms
. - The required endpoint generated by server.go for this challenge will be:
/cotacao
and theport
to be used by the HTTP server will be8080
.
- The
client.go
must make an HTTP request onserver.go
requesting the dollar quote. - The client will only need to receive from server the current exchange rate (JSON "bid" field).
- Using the
context
package, theclient
will have a maximum timeout of300ms
to receive the result fromserver
. - The
client
will have to save the current quote in a filecotacao.txt
in the format:Dollar: {value}
NOTE: some features not mentioned in the above trading rules have been implemented, such as the possibility to consult currencies other than the USD-BRL pair.
First, you will need do start the server, to do that perform the command below in your terminal.
go run cmd/server/server.go
So then you can test the client:
go run cmd/client/client.go GBP-BRL
{"name":"Libra Esterlina/Real Brasileiro","bid":"5.9507"}
Try other options:
- USD-BR
- EUR-BRL
In order to achieve to goal of this challenge you will see a file called cotacao.txt
which contains the exchange rate passed as parameter to the server
. Also, an SQLite3
database will be created to store each request to the server.
You can run the commands below to query the records:
$ sqlite3 cotacao.db
SQLite version 3.37.2 2022-01-06 13:25:41
Enter ".help" for usage hints.
sqlite> select * from exchange_rate;
1|Dólar Americano/Real Brasileiro|5.3257|2022-10-14 17:59:56
2|Euro/Real Brasileiro|5.1756|2022-10-14 17:59:56
3|Libra Esterlina/Real Brasileiro|5.9341|2022-10-14 14:24:34
sqlite>