This is a creation in Article, where the information may have evolved or changed.
Go language download install under Windows
Recommended for download in Golang China http://www.golangtc.com/download
Installation....
Go environment variables and working directory
According to the Convention Gopath need to build 3 directories
Bin (holds compiled executable file)
Pkg (holds the package file generated after compilation. a)
SRC (store project source code such as:. Go. C. H. S etc.)
Use Go env to view the environment
Common commands
Go get: Get remote package (git or HG (Google Code))
Go run: Run the program directly
Go bulid: Test compilation
Go FMT: Format source code
Go install: (Compile the package file and compile the entire program)
Go test: Run the testing file (e.g. Aa_test.go)
Godoc: Viewing documents (CHM manual)
Godoc FMT Println
Build your local website
godoc-http=:8080
Go built-in keywords
Break default Func Interface Select
Case defer go map struct chan
ELSE goto Package Switch Const Fallthrough
If range type continue for import return
Var
GO program is organized through the package (Python-like) an executable program There is only one main package Importing other non-main packages with the Import keyword by const To make a definition of production by using the Var keyword outside the body of the function To declare and assign a global variable declaring a function with the Func keyword |
Import of Packages
import "FMT"
import "OS"
import "IO"
or
Import (
"FMT"
"OS"
"IO"
)
After you import the package, you can use <PackageName>.<FuncName>
calling a function in a package
If a function or type is not called after the package is imported, a compilation error is reported
imported and not used: "IO"
Package aliases
When using a third-party package, the package name may be very close or identical,
At this point, you can use aliases to differentiate and invoke
Import (
FTD "FMT"
)
or import FTD "FMT"
Fmt. Println ("Hello word")
Omit call
Package Main Import " FMT " Func Main () { Println ("");}
Aliases must be used with aliases
Visibility rules
In the go language, use case to determine the constant, variable, type
Whether the interface, struct, or function can be called by an external package
Private if the first letter is lowercase according to the Convention function name
The first letter capitalized is public
Importing multiple packages can be abbreviated
Declaring multiple variables, global variables, or generic types (non-interfaces, non-structs) can also
Package MainImport "FMT"Const (PI=3.14KEY=123SEC=2) Var (a="HK"b="BBC") Type (name string age int sex int) func main () {FMT. Println ("Hello world! "+a+"\ r \ n"+b);}