Go Component Design

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

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.