Syntax
The alias is declared immediately preceding the package path string in theimport declaration.
Lexical Mechanics
- Identifier Replacement: Once a package is aliased, its original declared package name becomes inaccessible in that file. Attempting to reference the default name results in an
undeclared namecompilation error. - File-Level Scope: The alias is strictly scoped to the file containing the
importdeclaration. Other files within the same Go package must declare their own imports and are unaffected by aliases in adjacent files.
Special Alias Operators
Go defines two reserved alias operators that alter the standard namespace binding behavior: 1. The Blank Identifier (_)
Aliasing an import with the blank identifier prevents the compiler from binding the package to a local name. It executes the imported package’s init() functions and initializes its global variables, but the package’s exported identifiers remain inaccessible.
.)
Aliasing with a dot operator merges the imported package’s exported identifiers directly into the importing file’s lexical block. The exported members are accessed directly without any package qualifier.
Tired of Poor Go Skills? Fix That With Deep Grasping!Learn More





