This is a creation in Article, where the information may have evolved or changed.
Import is the role of importing other package, but today in the view of the Beego framework to see the import underline, do not know its meaning, so Baidu and solution.
import underscores (e.g. import _ Hello/imp): When importing a package, All init () function will be executed, however, there are times when we don't need to import the entire package, just want it to execute the init () function. You can use import to refer to the package at this time. Even if you refer to the package with the import _ package path only to invoke the Init () function, you cannot call other functions in the package by the package name.
Example
Directory structure:
Gopath
--bin
--pkg
--src
Main.go
--hello
--imp
Init.go
Main.go
1Package Main23Import _"Hello/imp"45Func Main () {6//Imp. Print () Compile error, said: Undefined:imp7}
Output: Imp-init () come here. 1Package Imp23Import"FMT"45func init () {6Fmt. Println ("Imp-init () come here.")7 }89func Print () {TenFmt. Println ("hello!") One}
As for the import point operation and alias operation is quite simple and understanding, so no longer demonstrated.