
The approach to Go project structure I described follows what's commonly known as the "Standard Go Project Layout" or "Go project directory structure conventions." It's not an official specification from the Go team, but rather a set of community-established best practices that have evolved over time.
When working with Go projects, adhere to the Standard Go Project Layout conventions:
-
Place executable entry points in the
cmd/directory, with each subdirectory representing a single binary. -
Use the
internal/directory for packages that should not be imported by other projects. -
Organize code into focused packages with single responsibilities.
-
Follow Go's standard naming conventions:
- CamelCase for exported names
- Short, lowercase package names
- Use
New[Type]for constructors
-
Place packages that may be imported by external applications in the
pkg/directory. -
Maintain clear separation of concerns between packages.
-
Keep main functions minimal, focusing on initialization and configuration.
-
Create small interfaces focused on the consumer's needs.
-
Pass context through function calls for cancellation support.
-
Follow idiomatic Go error handling patterns.
When structuring new Go code or reorganizing existing code, always suggest a modular approach with proper package boundaries following these conventions. Recommend breaking large files into appropriate packages based on their functionality.