This is a creation in Article, where the information may have evolved or changed.
1 About Go source code
Each go source code starts from the package {XXXX packet declaration }, which indicates that the go code belongs to this pack. Package is the most basic distribution unit of Go, and also the system of dependency in engineering management.
The go executable starts with the main function of the main package, and the main function has no parameters and no return.
Package Mainimport "FMT" //We need to use the println () function in the FMT packet func main () { fmt. Println ("Hello, World")}
2 Engineering Documents
Go using directory structure, folders to push the project structure, generally, to build a project requires three folders
If the project is placed in the catalogue/data/pro/demo <demo>├─<src>├─<libs>|--<event>hh.go├─<demo> ├─demo.go├─demo_hh.go├─demo_test.go├─<bin> #可执行文件目录 ├─<pkg># package will be installed here
Note that the project catalog must be
/data/pro/demo set to environment variable $GOPATH
2 Go Engineering Compilation installation
the revolutionary point of the GO command-line tool is to completely eliminate the concept of the project file, fully using the directory structure and the package name to derive the engineering structure and build order.
The construction project needs to add the project's root directory to the environment variable Gopath
In the directory where the main package is located, perform go install
All dependent packages can be compiled and installed into the PKG to compile the executable program into the bin
Additional Command instructions:
Go Build {xxx.go ... }
Go run compile and run
More Command Reference