The first Go program
Hello World
Now let's create the first Go Project - hello
. We GOPATH
create hello src directory under the directory.
Create a directory in the main.go
file:
. 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 build
It 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 GOPATH
to find you want to compile the src directory hello
project
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.exe
executable.
The terminal may be performed directly in the hello.exe
file:
1 d:\code\go\src\hello>hello.exe 2 Hello World!