This is a creation in Article, where the information may have evolved or changed.
Thought for a long time to learn a new language, tangled for a long time, finally chose the go language. Get started today with Go language learning.
1. Download go
Http://www.golangtc.com/download
2. Download Liteide
Http://www.golangtc.com/download/liteide
3. Start programming
The first program to learn any programming language is Hello World. Create the Hello.go file in the Gopath directory and enter the following.
-
package main
-
import "FMT" // Introduction of FMT library
-
func main () Span class= "PLN" > {
-
Span class= "PLN" > FMT println ( "Hello world!"
-
} /code>
Analyze This procedure line by row:
The first line is required. All files written in the Go language start with package <*> and must be the package main for running standalone files;
The second line indicates that the FMT package is added to main. Other packages, which are generally non-main, are called libraries,
The third line is the main function in the program. When the Go program executes, the function that is called first is the main function. This is inherited from C. Here is the function definition of the main function.
Line four calls the FMT package function to print the string to the screen. The string is wrapped by "" and can contain non-ASCII characters.
Note :
A standalone executable go program, the package main must appear, followed by the introduction of the various libraries, and then the individual functions, here must have a main function. The main function is the entry for the program.
Compile and run (using the win7 system, open cmd)
Use command: go build hello.go compile. The hello executable file for the. exe will be generated in the same directory.
Run:. hello exe
On-screen output: Hello World!
You can also use some parameters at compile time to reduce the size of the compiled file.
go build -ldflags "-s -w" hello.go