This is a creation in Article, where the information may have evolved or changed.
Our first example is to print the classic "Hello World" message, let's look at the code first.
Package Mainimport "FMT" Func Main () {FMT. Println ("Hello World")}
The output is:
$ lsel_01_hello_world.go$ Go build el_01_hello_world.go $ lsel_01_hello_world el_01_hello_world.go$./el_01_hello_ World Hello World
In order go文件 for a package name to be able to be, 编译 可执行文件 main then we import the package that provides the formatted output fmt , the execution entry of the program is the func main() function, inside the function, we use fmt the function provided by the package Println to output "Hello World "string.
In order to run this program, we can use it go run el_01_hello_world.go to run this example, which is to output the running result directly without producing any intermediate files. But sometimes we want to be able to compile the program into a binary file, and we can use it as above go build el_01_hello_world.go to compile the source code into a binary executable. Then we can run the binary executable directly.
Okay, so the first example is over. Very simple.