The main features of the Go language
Copy Code code as follows:
Automatic garbage collection
Richer built-in types
function multiple return value
Error handling
Anonymous functions and closures
Types and Interfaces
Concurrent programming
Reflection
Language interactivity
High performance/High efficiency development
Installation
Installation Instructions Address Http://golang.org/doc/install
Package Download Address Https://code.google.com/p/go/downloads/list
Confirm that the installation is successful
Copy Code code as follows:
Go version//view versions
environment variable Settings
Overall directory structure
With package organization, only the package name called main can contain the main function
A program has and has only one main package
Import other non main packages through the Import keyword
Copy Code code as follows:
bin/
|-Mathapp
pkg/
|-platform Name
|-XXX.A
src/
|-Mathapp
|-Main.go
Helloworld
Copy Code code as follows:
Package main//Declaration file Package
Import {
"FMT"//import package, cannot contain a package that is not used, otherwise the compilation error
}
Func Main () {//Entry function, no parameter no return value
Fmt. Println ("Hello World")
}
Run
$go Run Hello.go
$go Build Hello.go
$./hello
Go command
View with command line
Go Help
Copy Code code as follows:
Go build compilation
Go clean Removes the compiled build files from the current source package
Go FMT Format code
Go get dynamic Remote Code Pack
The go install generates the result file and compiles the results one to $gopath/pkg or $gopath/bin.
Go test Run the executable file for the test
Go Doc godoc-http=:8080 View document
Go fix repairs Previous versions of old code to new version
Go version View current versions
Go ENV view current GO's environment variables
Go list lists all currently installed package
Go run compile and run the Go Language program
Debugging
Using GDB for debugging, the go language is built inside
Copy Code code as follows:
List
Break
Delete
BackTrace
Info
Print
Whatis
Next
Continue
Set Variable
Editor settings
Vim
Other supplements
Comments
Copy Code code as follows:
Single
* *-----/multi-line
Import multiple Packages
Copy Code code as follows:
Call the function in the package
Copy Code code as follows: