November 2018
Intermediate to advanced
346 pages
8h 12m
English
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 ...
Read now
Unlock full access