go commands
go build
compile the package named by the import paths and thier dependencies
go build package/*.go
if build *.go, a virtual package command-line-arguments is created internally
$WORK/command-line-arguments/_obj/: stores the obj files
$WORK/command-line-arguments/_obj/exe/: stores the executable after link
-v - work
: print the name of the temporary work directory and do not delete it when exiting-n
: print the commands but do not run them-x
: as the-n
flag but run them
go install
compile and install the package and its dependent package. The result is archive/executable and installed to $GOBIN dir
If $GOBIN not set, error promption:
go install: no install location for directory
-o
flag currently is not acceptable for go installgo install only accepts *.go of cmd/executable src code, not *.go of lib src code. To install libs, need run
go install package
go get
- download/update specific package or their dependencies
-d
: only download the source code, no package installation-u
: update the named packages and their depenencies-fix
: for backword compatible
go list
list package information
- go list -json package: print the package strcuture in json format
- text/template syntax
1
2go list -f {{.ImportPath} package
go list -f {{.S.F}} package
1 | $ go list -json net/http |
go test
test *_test.go
go help testflag
-i
: install the test dependencies, but not compile and run it-c
: generate test executables, but not run it-bench regexp
执行相应的benchmarks,例如 -bench=.-cover
开启测试覆盖率-run regexp
只运行regexp匹配的函数,例如 -run=Array 执行包含有Array开头的函数
godoc
1 | $ go get golang.org/x/tools/cmd/godoc |
Reference
版权声明:本博客所有文章除特殊声明外,均采用 CC BY-NC 4.0 许可协议。转载请注明出处 Kasper Deng的博客!