Install the Go compiler
sudo apt-get-qy install Golang
Create a Go Project catalog (Gopath)
Mkdir-p ~/go/sample/
Create source Directory
mkdir ~/GO/SAMPLE/SRC
Create a sub-package directory
mkdir ~/go/sample/src/package
Create a library folder
mkdir ~/go/sample/src/package/subpackage
Write the Go Library code in the sub-sub-package directory
VI Hello.go
Package Subpackageimpot "FMT" func Hello () {//Here to note, the first letter of the Hello is capitalized so that the user can access the FMT. Print ("Hello, world!");}
Installation Library
CD ~/GO/SAMPLE/SRC
Go Install Package/subpackage
After installation, a PKG folder will be created under SRC, which will have a subpackage.a file
Using the Subpackage Library
Create another subfolder
mkdir ~/go/sample/src/package/subpackage1
Writing a file
VI World.go
Package Mainimport ("FMT," Package/subpackge ") func main () {FMT. Print ("main package~\n") Subpackage.hello ()}
Run the Go install package/subpackage1 in the SRC directory
After the command executes, a bin folder will be generated in the SRC sibling directory with the SubPackage1 executable file
If you want to run the SubPackage1 command directly, you can do the following:
Run under the SubPackage1 directory
Go build world.go (compile)
Go run World.go (run)
You can also directly
Go Run world.go
This article is from the "Precipice Program Ape" blog, please be sure to keep this source http://lth2015.blog.51cto.com/10613847/1683934
Go Project Management