Subpackage Visibility

How is the visibility of members from a subpackage in its root package?

Here is what I mean:

foo // the "root" package foo/utils // a sub-package foo/tools // another sub-package 

Can foo access private members foo/utils and foo/tools or do they act as separate independent packages?

+7
source share
1 answer

Go has no concept of subdirectories and subpackages. Packages are separated from each other. The import path "foo/utils" is just an import path (package search method) - the string "foo/utils" has no meaning other than locating the package on a local disk or on the Internet.

foo cannot access private members of foo/utils .

In Go1, each directory in the source tree corresponds to one package. You can learn more about this here: go command .

+11
source

All Articles