Overview of the Standard Go Project Layout
masterThis project provides a common layout pattern for Go projects. It is not an official standard defined by the Go development team, but rather a collection of patterns and best practices that have emerged from the Go ecosystem.
When to use this layout
- Avoid for small projects: If you are learning Go, building a Proof of Concept (PoC), or a simple experiment, do not use this complex structure. A single
main.goand ago.modfile are sufficient. - Use for growing projects: As your project grows, this layout helps manage dependencies, prevent global variable sprawl, and organize code for multiple contributors.
- Use for open source: When others will consume your code, using specific directories like
internalhelps protect private logic.
Key Recommendations
- Use Go Modules: Always use Go Modules (
go.mod) for dependency management. Ensure your module path contains a dot (e.g.,github.com/user/repo) to maintain compatibility with older Go versions. - Be Intentional: Do not feel obligated to use every directory listed in this layout. Clone this repository, take what you need, and delete the rest.