Go Keyword import: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 28: Line 28:


The <tt>package-name-alias</tt> is optional. If not specified, the package will be referred as the last segment of the path.
The <tt>package-name-alias</tt> is optional. If not specified, the package will be referred as the last segment of the path.
=Accessing an Identifier from an Imported Package=


=How Packages are Resolved=
=How Packages are Resolved=

Revision as of 03:27, 30 March 2016

External

Internal

Overview

An import declaration states that the current package depends on the functionality of the imported package and wants access to its name space. Thus, the current package gains access to the exported identifiers exposed by the imported package.

...
import [package-name-alias] "package-path-string-literal"
...

Example

...
import "lib/math"
...

The package path is enclosed in double quotes, it is a string literal.

The package-name-alias is optional. If not specified, the package will be referred as the last segment of the path.

Accessing an Identifier from an Imported Package

How Packages are Resolved

The algorithm is described here:

GOPATH