Are the following assertions about Go packages accurate?
import "package_name"
imports all files from the directory called package_name assuming is found in $GOPATH, a variable that holds the users go directory, or in the standard go installation directory tree.files within the package_name directory will usually state
package package_name
. But they are not required to. In fact,import "package_name"
, would also import a file including the linepackage foo
if the file was found in the imported package_name directory.All functions that are Capitalized will be accessed through the name given in the package package_name declaration--for instance:
package_name.Function_in_file_that_declares_package_name
or other_than_package_name.Function_in_file_that_declares_other_than_package_name
- User defined packages are command-line
go install
-ed from the within the package directory. However, go will refuse to install a directory named identically to its builtin package directories. For instance you cannot install a strings directory since go already has a strings directory for the builtin package "strings." However, the user can append functions to the strings package without altering the builtin strings folder, by creating a my_strings directory and the placing a file that statespackage strings
within it. Now,import my_strings
will load the extra user-defined strings functions accessed withstrings.Function_name
.
In summary, the import
keyword is used to load files from a given directory. And the keyword package
creates a namespace to access Capitalized functions from outside that file.
Am I understanding all of the above correctly?