November 2018
Intermediate to advanced
346 pages
8h 12m
English
Previously, in places where we called the data or exchange packages, we used context.TODO() to ensure the code could still compile and that our tests continued to do their job. It's now time to apply method injection to the model layer and replace the context.TODO() calls with injected context. First, we change the getPrice() and save() methods to accept a context:
// get price in the requested currencyfunc (r *Registerer) getPrice(ctx context.Context, currency string) (float64, error) { converter := &exchange.Converter{} price, err := converter.Do(ctx, config.App.BasePrice, currency) if err != nil { logging.L.Warn("failed to convert the price. err: %s", ...
Read now
Unlock full access