Junior · Modules and tooling
Package, module and repository
Why can a repository contain several packages but only one module path in one go.mod?
Try explaining this aloud before opening the answer. State your assumptions and trace a boundary case.
Reveal a strong answer
A package groups Go files compiled together in a directory, subject to build constraints. A module is a versioned set of packages rooted at go.mod; a repository is a version-control container and can hold multiple modules.
Import paths combine module path and package subdirectory. A nested go.mod creates a new module boundary; changes inside it may require its own tests and release version. Import cycles are rejected.
A v2+ module normally includes the major version suffix in its module/import path. internal packages enforce an import visibility boundary. A folder layout or repository rename can therefore change public API identity.
Common trap
A Git branch name or checkout directory is not the module import path.
Try it
A repository root is example.com/acme and contains cmd/api and internal/store. Which is the executable package?
Worked solution
cmd/api normally has package main and builds an executable; internal/store is an importable package restricted to the permitted parent tree. The module path still comes from go.mod. Verify with go list ./... instead of guessing from filenames.
Change the constraint
What changes if internal/store gains its own go.mod?
How did you do?
Self-assessment, not a compiler pass or interview score. Explain the reasoning unaided before marking understood.
Not marked. Progress stays on this browser, separate from course completion.
Primary references
Checked 2026-10-20. Use documentation for your pinned runtime, driver and tool version.