Golang mountains

Golang

Development Tools: vscode (tentative)

img

(1) go file extension is .go

Go the beginning of each file (2) must package xx, in order to declare which package belongs to, that is to say go go every language files must belong to a package.

(3) import “fmt”

After introduction represents a package, the package name FMT, is introduced into the bag, the bag can use this function, for example: fmt.Println ()

(4) func main(){

​ }

func is a keyword that represents a function.

main function name, is a main function, that is the entrance of our program.

(5) fmt.Println("hello")

It represents a function, the output of the contents of the package fmt call.

Go through the file mutate go build command to generate the .exe file.

img

Note: to switch to lower your main folder, and then use the dir command to see all the files in this folder, calls go build + command file name, it will generate an exe file.

img

This will execute the file, print out the content we want.

Can be directly go run + run file name, though not compiled exe file, but run slower, but in fact he was at the bottom experienced a compiler, because the computer does not recognize your go code.

In the real work, still use go build command.

Golang execution flow analysis

The following are two ways to perform the execution flow of papers

img

Two ways of execution flow difference

1) If we first compiled executable file, then we can copy the executable file to the machine does not go development environment
on the device, you can still run

2) If we go run go directly to the source code, so if you want to run on another machine, it needs to go development
environment, or can not execute.

3) At compile time, the compiler will depend on the program running in the library file that contains an executable file, the executable file bigger
lot.

Go program development notes (emphasis)

1) Go to the source file "go" for the extension.

2) Go application execution entry is main () function. This is the other programming languages ​​(such as java / c)

3) Go language strictly case-sensitive.

4) Go process consists of a statement, the statement does not require each semicolon (Go semicolon language automatically after each line), which also reflects the simplicity of Golang.

5) Go line by line compiler to compile, so we write a statement on his party, can not put multiple statements written in the same, whether
the error

6) or import variable defined in the language go if no packet that can compile the code.

7) braces are paired, are indispensable.

Guess you like

Origin www.cnblogs.com/chanyuli/p/11588479.html