Applying config injection to the data package

Our data package is currently based on functions, and as such, the changes are going to be a little different compared to the previous ones. Here is a typical function from the data package:

// Load will attempt to load and return a person.// It will return ErrNotFound when the requested person does not exist.// Any other errors returned are caused by the underlying database // or our connection to it.func Load(ctx context.Context, ID int) (*Person, error) {   db, err := getDB()   if err != nil {      logging.L.Error("failed to get DB connection. err: %s", err)      return nil, err   }   // set latency budget for the database call   subCtx, cancel := context.WithTimeout(ctx, 1*time.Second)   defer cancel()   // perform ...

Get Hands-On Dependency Injection in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.