GO language - the first step into the pit

The first Go program

Hello World

Now let's create the first Go Project - hello. We GOPATHcreate hello src directory under the directory.

Create a directory in the main.gofile:

  . 1 Package main  		 // declare main package, that the current is an executable program 
  2  
  . 3  Import " fmt "  		 // Import built package fmt 
  . 4  
  . 5 FUNC main () {  		 // main function, a program executed entry 
  . 6  	fmt.Println ( " Hello World! ")  	 // prints Hello World in the terminal! 
  7 }
go build

go buildIt said it will compile source code into executable files.

Hello executed in catalog:

  1 go build

Or execute the following command in a different directory:

  1 go build hello

will go to the compiler GOPATHto find you want to compile the src directory helloproject

Been compiled executable file will be saved in the current directory compile command if the windows platform is to be found in the current directory hello.exeexecutable.

The terminal may be performed directly in the hello.exefile:

  1 d:\code\go\src\hello>hello.exe
  2 Hello World!



Classification: GO language


Guess you like

Origin www.cnblogs.com/lz1996/p/11984851.html