1. 打印 hello world
  1. // file_name: hello_world.go
  2. package main
  3. import "fmt"
  4. func main() {
  5. fmt.Println("Hello, world")
  6. }

2. 编译
  1. 以脚本运行

    1. [root@VM-8-5-centos syntax]# go run hello-word.go
    2. Hello, world
  2. 生成二进制文件

    1. [root@VM-8-5-centos syntax]# go build hello-word.go
    2. [root@VM-8-5-centos syntax]# ls
    3. hello-word hello-word.go
    4. [root@VM-8-5-centos syntax]# ./hello-word
    5. Hello, world