Skip to content

patricksegantine/goexpert-client-server-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Expert Challenge

Topics covered in this challenge:

  • Webserver http
  • context
  • database
  • file

Prerequisites

  • Go
  • SQLite3

Business rules

The requirements to meet this challenge are:

Server

  1. 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 .
  2. 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 be 200ms and the maximum timeout to be able to persist the data in the database should be 10ms.
  3. The required endpoint generated by server.go for this challenge will be: /cotacao and the port to be used by the HTTP server will be 8080.

Client

  1. The client.go must make an HTTP request on server.go requesting the dollar quote.
  2. The client will only need to receive from server the current exchange rate (JSON "bid" field).
  3. Using the context package, the client will have a maximum timeout of 300ms to receive the result from server.
  4. The client will have to save the current quote in a file cotacao.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.

How to run it?

First, you will need do start the server, to do that perform the command below in your terminal.

Server

go run cmd/server/server.go

So then you can test the client:

Client

go run cmd/client/client.go GBP-BRL
{"name":"Libra Esterlina/Real Brasileiro","bid":"5.9507"}

Try other options:

  • USD-BR
  • EUR-BRL

Expected result

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>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages