Go packages are constructed from one or more source files, which are organized into folders in the file system. Source files of the same package must be in the same folder.
But in Go there is no "package hierarchy", the "subpackage" term simply refers to the folder of a package being a subfolder of another. We often organize packages to be in folders being subfolders of others because there is some connection between those packages (e.g. a package is used only by another being in the parent folder; or a package in a subfolder is a specific or more special implementation of the package in the parent folder; or simply just a logical grouping - see the end of the answer).
So whenever you do
It only imports
pkgfoo and no other packages sharing the same path as prefix. If you need
github.com/usera/pkgfoo/subpkg too, you also need to explicitly import it:
import ( "github.com/usera/pkgfoo" "github.com/usera/pkgfoo/subpkg" }
The Go Blog: Package names on directories used in the standard library:
Directories. The standard library uses like directories
imageto group packages for related protocols and algorithms. There is no actual relationship among the packages in one of these directories; a directory just provides a way to arrange the files. Any package can import any other package provided the import does not create a cycle.