OneTutorial - A practical journey into the Golang Programming Language
This little project will help you touch many topics around Golang, in a small and contained way.
What you will build
You can adjust the tutorial to your needs, but I find it more usefull to create something you will actually use. Therefore:
Update and read from a Google Sheet where you store your latest financial information and send out an E-Mail with a summary.
This can be adjuste to:
Update and read from a CSV file where you store your latest financial information and send out an E-Mail with a summary.
If you are not interested in the topic (finance), feel free to adjust it to whatever data inputs you consume a lot and want to automise.
Before you begin
If you want to go down the Google Sheets route, you need to:
- Create a "Service Account" via the Google Console.
- Create a key which downloads a JSON file you need for the library we are going to use.
- Create a new Google Sheet and share it with the Service Account E-Mail so the secret you just downloaded can read and modify the Google Sheet.
Depending on which external APIs you are going to use, you need to create API keys for them as well. For this tutorial, I am using:
- The coinmarketcap.com API to fetch the latest Crypto prices
- The eodhistoricaldata.com API to fetch ETF prices
The Tutorial
- Send a GET request to https://httpbin.org/ip and print the result to the console.
- Send out a request to CMC and fetch the price of BTC.
- Read the API key from an .env file.
- Get the name, symbol, price and 7day of the BTC and store it in a struct.
- Pass the list of currencies to fetch via the CLI.
- Save the result in a CSV file.
- In case the API returns an error, write it out to a log file and abort the application.
- In addition to the coin prices, fetch the price of a random ETF and store it also in a struct.
- Add a rows in your Google Sheet with ISN, amount of coins, price, total and a row with the total value of your portfolio.
- Instead of saving the result to a CSV, update your Google sheet.
- Move out your business logic in different modules.
- Build your Rust code and move the binary to a server and run it from there.
- Send out an E-Mail with the coin and ETF overview and redeploy your application/binary.