include - Are the following assertions about Go packages accurate? -
are following assertions go packages accurate?
import "package_name"
imports files directory called package_name assuming found in $gopath, variable holds users go directory, or in standard go installation directory tree.files within package_name directory state
package package_name
. not required to. in fact,import "package_name"
, import file including linepackage foo
if file found in imported package_name directory.all functions capitalized accessed through name given in 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 command-line
go install
-ed within package directory. however, go refuse install directory named identically builtin package directories. instance cannot install strings directory since go has strings directory builtin package "strings." however, user can append functions strings package without altering builtin strings folder, creating my_strings directory , placing file statespackage strings
within it. now,import my_strings
load user-defined strings functions accessedstrings.function_name
.
in summary, import
keyword used load files given directory. , keyword package
creates namespace access capitalized functions outside file.
am understanding of above correctly?
the argument of "import" import_path, not package name. makes exported entities package found in
$gopath/src/import_path
available in file scope "import" clause appears.all *.go files, except
*_test.go
files , files// +build ignore
, in single directory must same name inpackage name
clause or go build system reject it.not capitalized, belonging unicode category lu. not functions tld entity.
no, can go-install package directory using import path. yes, packages stdlib have priority , cannot "overriden". however, can "replace" stdlib package using eg.
import strings "github.com/foo/mystrings"
. however, effect local/file only.
in summary, no, import used make entities other packages available in file scope. keyword "package" creates no namespace. effect of "import" file-scoped, see preceding sentence , imported entities referred qualified names. qualifier sort of namespace, note not "exporter" (package foo
) controls that. instead control @ "importer" side: import whatever_local_name "whatever_import_path"
. default qualifier basename of import path, though.
"do agree?"
not @ all.
Comments
Post a Comment