first, about the installation and configuration of the Go development environmentTo install the compiled go installer in a Linux environment, refer to the official Guide steps step by step. It is important to note the following configuration of the environment variables:
Goroot-Directory of Go compiler libraries, similar to Java java_home
PATH-Pay attention to adding $goroot/bin
Gopath-Go working directory, similar to Eclipse's workspace below are the specific installation steps and environment configuration
$ wget https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
$ tar-c/usr/local-xzf go1.6.linux-amd64.tar.gz
The installation directory is/usr/local/go, and the working directory is/usr/local/golang/work. Add environment variables to the/ect/profile file for global effect.
Second, the Code organization of Go Project Typical go working directory typically contains 3 directories $GOPATH/ bin/ &NB Sp # binary execution file output Out path, typically generated automatically by Go compiler pkg/ &NBS P # Intermediate library files, automatically generated by the go compiler, sorted out by different OS architecture platforms &NBSP ; linux_amd64/ # Linux 64bit &NBSP ; windows_amd64/ # windows 64bit &NB Sp src/ &NBSP ; # hand-created, store all go source files and store them in different sub-directories by package GITHUB.COM/[USER]/XXX &NBSP # requires Git to manage versions, recommended directory structure
- It is recommended that all go codes be placed in a single working directory (i.e. the directory that $gopath points to)
- A working directory can contain different version control libraries (Git repository)
- Each version control library can contain one or more packages
- Each package contains one or more go source files (Note that multiple go files of the same package need to be placed in the same directory, the package name must be the same, the recommended package name is the last level of the current directory path.) For example, if the go file is stored in the $gopath/src/test1/stringutil directory, the package name is Stringutil)
- Introducing a package (import) is the path to the directory where the package is located (relative to the $GOPATH/SRC path)
GO1.6 Language Learning Note 2-installation configuration and Code organization