install
以Linux环境为例。
1 | # downlaod in China |
proxy config
首先配置代理,方便后续的模块下载
1 | go env -w GO111MODULE=on |
Command
common
go 的一些常用命令
1 | # 运行当前目录main包内的main函数 |
mod
1 | mkdir hello |
创建一个新模块, 模块就是go的最小分发单位。可以后续将这个模块publish,共享给其他人使用
When you ran
go mod tidy, it located and downloaded thersc.io/quotemodule that contains the package you imported. By default, it downloaded the latest version – v1.5.2.
run
run 命令的作用是编译和运行,且不会产生可执行的文件,一般用于调试开发使用。
While the
go runcommand is a useful shortcut for compiling and running a program when you’re making frequent changes, it doesn’t generate a binary executable.
test
测试命令可以运行所有的测试函数,测试函数的名称以 Test开始,且test文件必须要以 xxx_test.go 进行命名。可以添加-v 获得详细的输出
The
go testcommand executes test functions (whose names begin withTest) in test files (whose names end with _test.go). You can add the-vflag to get verbose output that lists all of the tests and their results.
build
build 命令会生成当前项目的可执行文件