Structuring applications in Go

Click for: original source

An article by Liam Andrew Cura about his Gog journey. For him the hardest part of learning Go was in structuring his application.

Go doesn’t prescribe any particular project layout or application structure and Go’s conventions are mostly stylistic.

Author focuses on four patterns which can be tremendously helpful in creating architecture for Go application:

  • Don’t use global variables
  • Separate your binary from your application
  • Wrap types for application-specific context
  • Don’t go crazy with sub-packages

Go only has one requirement for packages: you can’t have cyclic dependencies. Author recommends to group related types and code together in each file. Also organize the most important type at the top of the file and add types in decreasing importance towards the bottom of the file.

Well written article with code examples and links to complementary resources and reading. Excellent!

[Read More]

Tags golang web-development programming software-architecture