Every Go program is made up of packages. Programs start running in package
By convention, the package name is the same as the last element of the import path. For instance, the “
math/rand” package comprises files that begin with the statement
package rand, in
math/rand will not be accessible in
math package unless imported.
Packages are given lower case, single-word names. The importer of a package will use the name to refer to its contents, so exported names in the package can use that fact to avoid stutter. For instance, the buffered reader type in the
bufio package is called
BufReader, because users see it as
bufio.Reader, which is a clear, concise name.
You can import one package per line, such as
import "fmt" import "math"
But the convention is to use “factored” import statement:
import ( "fmt" "math" )
When a package is imported, the package name becomes an accessor for the contents. After
the importing package can talk about
Go is strict about importing packages. It will not compile if you import a package but don’t use it.
Cyclical imports are not allowed and will result in compile-time error.
In Go, a name is exported if it begins with a capital letter. For example,
Pizza is an exported name, as is
Pi, which is exported from the math package.
pi do not start with a capital letter, so they are not exported.
When importing a package, you can refer only to its exported names. Any “unexported” names are not accessible from outside the package.
go get command can fetch third-party libraries. If it is invoked in a project, it will scan all the fiels, looking for
imports to third-party libraries and will download them.