Our AI writing assistant, WriteUp, can assist you in easily writing any text. Click here to experience its capabilities.

Standard Package Layout

Summary

This article discusses the issue of application package layout in the Go community, and proposes a better approach to designing Go applications. It suggests that the root package should contain domain types, subpackages should be grouped by dependency, a shared mock subpackage should be used for testing, and the main package should tie all of the dependencies together. The article also looks at some of the most common approaches to Go application organization, and highlights the flaws of each one.

Q&As

What are the common flawed approaches to application package layout in Go?
The common flawed approaches to application package layout in Go are monolithic package, Rails-style layout, and group by module.

What are the benefits of grouping subpackages by dependency in Go?
The benefits of grouping subpackages by dependency in Go are that it isolates dependencies, simplifies testing, provides an easy way to migrate to another database in the future, and gives a way to layer implementations.

What are the four tenets of a better approach to package layout in Go?
The four tenets of a better approach to package layout in Go are root package is for domain types, group subpackages by dependency, use a shared mock subpackage, and main package ties together dependencies.

How does the main package of a Go application tie together its dependencies?
The main package of a Go application ties together its dependencies by injecting them at compile time and connecting the terminal to the domain.

What are the benefits of approaching design from the standpoint of dependencies in Go?
The benefits of approaching design from the standpoint of dependencies in Go are that it makes code organization simpler and easier to reason about, isolates dependencies, and introduces mocks to isolate tests.

AI Comments

👍 Great article on application package layout for Go applications! It outlines some common approaches and provides a better approach with useful rules to follow.

👎 This article was too verbose and didn't provide enough practical examples to help understand the principles outlined.

AI Discussion

Me: It's about package layout for Go applications. It talks about the flaws of some common approaches, and suggests a better way to organize code by following a few simple rules. It's an interesting read.

Friend: Interesting. What are the implications of the article?

Me: The article suggests that the best way to approach package layout is to organize code by dependency, use a shared mock subpackage for testing, and keep the main package as an adapter between your domain and the implementation. This approach can help simplify code organization and make it easier to reason about and test. It also provides an easy way to migrate to another database or switch to a different third-party service without affecting other dependencies.

Action items

Technical terms

Vendoring
A process of managing dependencies in a project by copying the dependencies into the project’s source code repository.
Generics
A feature of a programming language that allows the same code to be used with different types of data.
SLOC
Source Lines of Code, a measure of the size of a software program.
BoltDB
A key/value database written in Go.
Dependency Injection
A technique for decoupling the creation of objects from their usage. It allows for the passing of dependencies into an object instead of the object creating or finding them itself.

Similar articles

0.9042538 The one-and-only, must-have, eternal Go project layout

0.90422326 The one-and-only, must-have, eternal Go project layout

0.8452989 Where Is the Spring Framework for Go?

0.81726605 The Data Æther

0.8109192 Software engineers hate code.

🗳️ Do you like the summary? Please join our survey and vote on new features!