Giter VIP home page Giter VIP logo

cambiodolar's Introduction

CambioDolar

Chalange Client-Server API

This little API follows the requirements of the task suggested by FullCycle in the GoExpert course.

The task is:

Você precisará nos entregar dois sistemas em Go:
- client.go
- server.go

Os requisitos para cumprir este desafio são:

O client.go deverá realizar uma requisição HTTP no server.go solicitando a cotação do dólar.

O server.go deverá consumir a API contendo o câmbio de Dólar e Real no endereço: https://economia.awesomeapi.com.br/json/last/USD-BRL e em seguida deverá retornar no formato JSON o resultado para o cliente.

Usando o package "context", o server.go deverá registrar no banco de dados SQLite cada cotação recebida, sendo que o timeout máximo para chamar a API de cotação do dólar deverá ser de 200ms e o timeout máximo para conseguir persistir os dados no banco deverá ser de 10ms.

O client.go precisará receber do server.go apenas o valor atual do câmbio (campo "bid" do JSON). Utilizando o package "context", o client.go terá um timeout máximo de 300ms para receber o resultado do server.go.

O client.go terá que salvar a cotação atual em um arquivo "cotacao.txt" no formato: Dólar: {valor}

O endpoint necessário gerado pelo server.go para este desafio será: /cotacao e a porta a ser utilizada pelo servidor HTTP será a 8080.

Ao finalizar, envie o link do repositório para correção.

Requirements

  • You need to have installed locally:
    • Golang (version > 1.19)
    • Sqlite3

Run the API

  1. Clone/download the repository to a local folder;

  2. Via terminal, access the cloned repository folder;

  3. Run this command to start the API:

  • go run main.go
  1. Access this link through the browser to see the result:
  • localhost:8080/cotacao
  • DETAIL: if the API return a log with context deadline exceeded, reload the browser page.

Result

  • After accessing the localhost link, the result of the API will appear in the browser screen.

  • Two files will be created in the main project folder if all goes well:

    • A txt file called cotacao.txt, containing the dollar quotation value in reais at the time you make the request.
    • A db file called cambio_dolar.db, containing the Sqlite database records.

SqLite DB:

If you want to see the result in Sqlite database, run the these commands in another terminal:

  1. You need to have the sqlite3 installed to run this command:
  • sqlite3
  1. Check if the table cotacoes was successfully created running the following command:
  • .tables
  1. Get the result of the table cotacoes running the following command:
  • select * from cotacoes;

cambiodolar's People

Contributors

artusandermann avatar artusc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.