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

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

Summary

This article discusses the various ways to lay out a Go project, with the focus being on the architecture and naming of components. While there is no single "standard" Go project layout, best practices can be followed to ensure the layout is useful. Depending on the project, different layouts may be more applicable. For example, a simple CLI tool may require only a single directory, while a large application project could benefit from a "Standard Go Project Layout" which includes a pkg directory. While this directory can be beneficial for larger projects, it is not necessary for smaller projects and can result in longer import paths. The article goes on to discuss the pros and cons of using a pkg directory, and provides advice on how to decide if this directory should be used.

Q&As

What is the Go proverb discussed in the article?
The Go proverb discussed in the article is "Design the architecture, name the components, document the details."

Why is there no single Go project layout?
There is no single Go project layout because different project types have different needs.

What are the best practices for laying out a Go project?
The best practices for laying out a Go project are to start small, name packages by their functionality, follow the few conventions, and do not use a "src" directory.

What is the Standard Go Project Layout?
The Standard Go Project Layout is a project template that showcases how a full-featured project layout can look like.

What is the recommended layout for large application projects?
The recommended layout for large application projects is to use a pkg directory to keep the repository layout consistent and navigable, and to isolate Go code from non-Go assets.

AI Comments

👍 This article provides insightful advice on how to develop a Go project layout and the benefits of using a pkg directory.

👎 The quotes and advice presented in this article can be confusing for newcomers to the Go community.

AI Discussion

Me: It's about the optimal Go project layout and how there is no single standard layout. It talks about different types of projects, such as CLI tools, pure library projects, CLI tools with public packages, and large mixed-language projects, and the best practices for each type. It also discusses the pros and cons of using a "pkg" directory.

Friend: Interesting. It sounds like the article is saying that the optimal Go project layout really depends on the project type.

Me: Exactly. It's important to think about what type of project you're working on and design the layout accordingly. For example, for small projects, you may not need to use a "pkg" directory, but for larger projects, it could be beneficial. It's also important to follow best practices for naming components and packages so that your project is readable and navigable.

Action items

Technical terms

Go project layout
The structure of a Go project, which includes the organization of files and directories.
Go proverbs
A list of proverbs presented by Rob Pike at a talk at Gopherfest 2015.
Go module
A collection of related Go packages that are versioned together as a single unit.
Semantic versioning
A versioning system that uses a three-part version number (major.minor.patch) to indicate the level of changes in a release.
Internal directory
A directory in a Go project that contains packages that are not accessible outside the Go module it belongs to.
Testdata directory
A directory in a Go project that contains ancillary test data that is ignored by the Go toolchain.
Vendor directory
A directory in a Go project that contains all 3rd-party dependencies.
Public API
A package that is exposed to the public and must follow semantic versioning.
Framework
A rigid structure that might or might not match the project's specific needs.
Cmd directory
A directory in a Go project that contains code for command-line tools.
Pkg directory
A directory in a Go project that contains library packages for public use.
GOPATH
The single Go workspace prior to Go Modules.

Similar articles

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

0.90422326 Standard Package Layout

0.8427036 Where Is the Spring Framework for Go?

0.83255905 Non-Traditional Project Planning

0.81878376 One Big Web: A Few Ways the World Works

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