go version go1.12.4 linux/amd64
源码
模块和包
语言系统
go help : 查看 go 源码管理工具.
go help command : 查看某个工具(command)的用法, 如 go help run.
pxx 表示包
dxx 表示目录
fxx 表示文件
格式
参数
例子
go run fxx.go //编译并运行(fxx)
go run fxx.go argxxx //argxxx 是传给编译出来的可执行程序(dxx)的参数
go run dxx //编译并运行(dxx)
go run dxx argxxx //argxxx 是传给编译出来的可执行程序(dxx)的参数
?这个命令不会产生新文件
参数
例子
main 包
go build fxx.go //当前目录下编译出fxx
go build /path/to/dxx //当前目录下编译出dxx
?非 main 包,编译后舍弃.什么叫舍弃?生成一些临时文件和 cache 又删了.可以加 -n 编译 main 包和非 main 包,比较发现 main 包最后多了一行类似 mv $WORK/b001/exe/a.out dxx,把 cache 里生成的可执行程序(a.out) 移到当前目录下并重命名 (dxx)
go clean 清除 go 工具和 makefile 产生的临时文件和各种 cache\
参数
例子
go clean
格式
go fmt 格式化源码文件
参数
例子
go fmt fxx //文件
go fmt dxx //目录/包
go fmt dxx/... //递归
?go fmt 调用 gofmt -l -w,了解更多请看 go doc gofmt.
参数
?go help testflag 查看更多参数
-bench 基准测试
-cover 测试覆盖分析
-coverprofile cover.out 输出覆盖分析文件
-cpuprofile cpu.out 输出cpu分析文件
-memprofile mem.out 输出内存分析文件
例子
go test //测试当前包,禁止cache
go test . //测试 . 目录
go test dxx/... //递归测试 dxx 目录
go test dxx //测试 dxx 目录
go test fxx //测试 fxx 文件
格式
go generate //执行预先写在文档中的命令,格式 //go:generate command argument…
参数
参数
例子
go vet fxx //文件的绝对路径或相对路径
go vet pkgxxx //包导入路径
格式
go mod [arguments]
参数
例子
go mod init
go mod init /import/path/pkg
go mod vendor
go list
go list pxx
go list …
go list pxx/…
go list -json pxx/…
gopath/to/import/pxx
格式
go get /import/path/to/pxx
参数
例子
go tool //打印所有命令
go tool pprof //执行 pprof 命令
go tool -n pprof //显示但不执行 pprof 命令
go tool [-n] command [args…]
格式
go doc pkg/sym/field
参数
例子
go doc //当前包
go doc Foo //当前包符号 Foo
go doc encoding/json //encoding/json 包
go doc json //encoding/json 包简写
go doc json.Number //Number 文档和方法
go doc json.Number.Int64 // Int64 方法的文档
go env // 打印 go 环境变量
go env GOPATH // 打印 GOPATH 环境变量
go env -json // json 格式显示 go 环境变量
go version //打印版本号
待续