November 2018
Intermediate to advanced
346 pages
8h 12m
English
The exchange package is responsible for loading the current currency exchange rate (for example, Malaysian Ringgit to Australian Dollars) from an upstream service. Similar to the data package, it provides simplified and abstracted access to this data.
The following are the relevant parts of the current code:
// Converter will convert the base price to the currency suppliedtype Converter struct{}// Do will perform the loadfunc (c *Converter) Do(basePrice float64, currency string) (float64, error) { // load rate from the external API response, err := c.loadRateFromServer(currency) if err != nil { return defaultPrice, err } // extract rate from response rate, err := c.extractRate(response,
Read now
Unlock full access