Go Component Design: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Go Engineering =Organizatorium= Prefer this style: <syntaxhighlight lang='go'> func main() { cfg := GetConfig() db, err := Conn...")
 
Line 19: Line 19:
}
}
</syntaxhighlight>
</syntaxhighlight>
This allows building the mental model of the components, and nothing is obscured behind layers of indirection.

Revision as of 19:12, 22 December 2023

Internal

Organizatorium

Prefer this style:

func main() {
  cfg := GetConfig()
  db, err := ConnectDatabase(cfg.URN)
  if err != nil {
    panic(err)
  }
  repo := NewPersonRepository(db)
  service := NewPersonService(cfg.AccessToken, repo)
  server := NewServer(cfg.ListenAddr, service)
  server.Run()
}

This allows building the mental model of the components, and nothing is obscured behind layers of indirection.