第一个go程序
helloworld.go
package main
import "fmt"
func main() {
fmt.Println("vim-go")
fmt.Println("hello world!")
}
1 当前为main包,是程序的主入口包;
2 导入 fmt 包
3 程序执行入口 main 函数
- 使用 go run 执行以上代码
$ go run helloworld.go
vim-go
hello world!
- 使用 go build 生成二进制文件
$ go build helloworld.go
$ ./helloworld
vim-go
hello world!
- 代码链接,后续会有不断更新:
https://github.com/DefangHe/go-study
本文介绍如何使用Go语言编写第一个程序“HelloWorld”,包括创建main包、导入fmt包、定义main函数,并演示了使用gorun和gobuild执行和编译程序的方法。

被折叠的 条评论
为什么被折叠?



