November 2018
Intermediate to advanced
346 pages
8h 12m
English
Often times, your first instinct will be to inject a dependency so that you can test your code in isolation. However, to do so, you are forced to introduce so much abstraction and indirection that the amount of code and complexity increases exponentially.
One widespread occurrence of this is using the common library for accessing external resources, such as network resources, files, or databases. Let's use our sample service's data package, for example. If we wanted to abstract our usage of the sql package, we would likely start by defining an interface, as shown in the following code:
type Connection interface { QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row QueryContext ...
Read now
Unlock full access