The most important feature of Go
Automatic garbage collection
More richer built-in types
Functions return values
Error handling
Anonymous functions and closures
Types and interfaces
Concurrent programming
reflection
Language Interaction
High performance/efficient development
Install
Installation Instructions Address/doc/install
Package download address/p/go/downloads/list
Confirm whether the installation is successful
go version //View version
Environment variable settings
Overall directory structure
Organized through package, only the main function can be included with the package name main
A program has and only one main package
Import other non-main packages through import keyword
bin/
|- mathapp
pkg/
|- Platform name
|-
src/
|- mathapp
|-
Helloworld
package main //Declare file package
import {
"fmt" //import package, cannot contain unused packages, otherwise there will be a compile error
}
func main() { //Entrance function, no parameters, no return value
("hello world")
}
//run
$go run
$go build
$./hello
go command
View with the command line
go help
go build
go clean Removes the compiled file in the current source code package
go fmt format code
go get dynamically obtaining remote code packages
go install generates the result file and transfer the compiled result to $GOPATH/pkg or $GOPATH/bin
go test Executable file for running tests
go doc godoc -http=:8080 View the document
go fix fix to fix the old version of the previous version of the code to the new version
go version to view the current version
go env to view the current go environment variables
go list list all currently installed packages
go run Compile and run go language program
debug
Use gdb for debugging, the go language is already built into
list
break
delete
backtrace
info
whatis
next
continue
set variable
Editor Settings
vim
Other supplements
Comments
//Single line
/* ----- */ Multiple lines
import multiple packages
import (
"fmt"
"os"
)
Calling functions in packages
<packageName>.<Function>