Adopting Google Wire

The first thing we need to do, however, is to get our house in order. Most, if not all, of the objects we are going to let Wire handle use our *config.Config object, and currently it exists as a global singleton, as shown in the following code:

// App is the application configvar App *Config// Load returns the config loaded from environmentfunc init() {   filename, found := os.LookupEnv(DefaultEnvVar)   if !found {      logging.L.Error("failed to locate file specified by %s", DefaultEnvVar)      return   }   _ = load(filename)}func load(filename string) error {   App = &Config{}   bytes, err := ioutil.ReadFile(filename)   if err != nil {      logging.L.Error("failed to read config file. err: %s", err)      return err   }   err = json.Unmarshal(bytes, App ...

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.