4. Kubernetes Deep Dive
Activity 4: Collect Gold Prices in a MySQL Database in Kubernetes
Solution:
Execute the following steps to complete this activity:
- Create an application to retrieve the gold price from
CurrencyLayer
and insert it into the MySQL database.It is possible to implement this function in Go with the following main.go file:
... func main() { db, err := sql.Open("mysql", ... ... r, err := http.Get(fmt.Sprintf(„http://apilayer.net/api/... ... stmt, err := db.Prepare("INSERT INTO GoldPrices(price) VALUES(?)") ... _, err = stmt.Exec(target.Quotes.USDXAU) ... log.Printf("Successfully inserted the price: %v", target.Quotes.USDXAU) ... }
The main function starts with database connection...