At the moment need to have installed Go
and MongoDB
to use this code
See the section Running the app with docker-compose
This API
try to get the best price (purchase and sale) of currencies from multiple Operators
- Clone this repo using
git clone https://github.com/wchopite/golang-mongo-api.git
- Rename the file
.env.example
to.env
and setup the environment vars - Run the application with
go run main.go
- Access
http://localhost:1337/api/currency
Each request to the API must include the following headers:
Content-Type: "application/json"
- Create a
currency price
using thePOST /api/currency
endpoint and the next payload (for example):
{
"coin" : "USD",
"purchase_value" : 60.58,
"sale_value" : 58.59,
"operator" : "Santander"
}
- Then, you can use the other endpoint
GET /api/currency
. This endpoint return (for example):
[
{
"Coin": "EUR",
"Purchase_value": 65,
"Sale_value": 69,
"Operator": "Banco Nacion"
},
{
"Coin": "USD",
"Purchase_value": 61.5,
"Sale_value": 57.5,
"Operator": "Banco Nacion"
}
]
You can get the best value only for one currency
using in the query params
the var key
(this var represent the currency). For example:
GET /api/currency?key=USD
The return value:
[
{
"Coin": "USD",
"Purchase_value": 61.5,
"Sale_value": 57.5,
"Operator": "Banco Nacion"
}
]
Working in Progress
Install Docker
: https://docs.docker.com/compose/install/Install Docker Compose
: https://docs.docker.com/compose/install/
Once you have installed them, in the root folder you need to run docker-compose up
. This command generate the containers with the go app and mongo database
. Then you can test it using a Restful client, like Postman
- Golang: https://golang.org/
- Gorilla Mux: https://github.com/gorilla/mux
- MongoDb: https://docs.mongodb.com/manual/
- MongoDb Driver for go: https://docs.mongodb.com/ecosystem/drivers/go/
- Godotenv: https://github.com/joho/godotenv
- Add
unit and integration test
- Add input validation on endpoints
- Add
coverage
- Add a
cache layer
withredis
for example - A better code organization. Divide in a better way the multiple layers
- Add files configuration to
CI/CD
(codeship, google cloud build, etc) - Keep learning about
Go
, best practices, standards - Patterns, patterns, patterns...