go语言之go run/build/install/get

go run

 用于运行命令源码文件,只能接受一个命令源码文件以及若干个库文件作为参数
  • go run 命令的常用标记参数:
    • -a :强制编译相关代码
    • -n:打印编译过程中所用的命令,但并不执行编译过程
    • -x: 打印编译过程所需运行的命令,并执行编译;(注意和-n标记的区别)
    • -p N :并行编译,其中N为并行的数量 (可以是逻辑cpu的个数),可以加速我们的编译速度
    • -v:列出被编译的代码包的名称
    • -work:显示编译时的临时工作目录的路径,并且不删除它
Inspiron-5759:~/goc2p/src/helper/ds$ go run -v showds.go 
command-line-arguments
goc2p/src/helper/ds:
  showds.go
goc2p/src/helper/ds$ go run -work showds.go 
WORK=/tmp/go-build114678238
/home/emindsoft/workdir/golang/xztlearn/goc2p/src/helper/ds:
  showds.go

go build

  • 命令用于编译源码文件或代码包
  • 编译非命令源码文件不会产生任何结果文件,只检查库文件的有效性;

    • 编译命令源码文件时会在执行目录下生成可执行文件;
    • 不加任何参数,会把当前目录作为代码包并编译;
    • 执行该命令且以代码包的导入路径作为参数时,改代码包及其依赖会被编译;
    • 执行该命令且以若干源码文件作为参数时,只有这些文件会被编译;
  • go build 命令的常用标记和go run 命令基本一致;

go install

  • 编译并安装代码包或者源码文件
  • 产生归档文件和可执行文件(默认为当前目录)
emindsoft@emindsoft-Inspiron-5759:~/workdir/golang/xztlearn/goc2p/src$ go help install
usage: go install [build flags] [packages]

Install compiles and installs the packages named by the import paths,
along with their dependencies.

For more about the build flags, see 'go help build'.
For more about specifying packages, see 'go help packages'.

See also: go build, go get, go clean.
  • go get
Get downloads and installs the packages named by the import paths,
along with their dependencies.

The -d flag instructs get to stop after downloading the packages; that is,
it instructs get not to install the packages.

The -f flag, valid only when -u is set, forces get -u not to verify that
each package has been checked out from the source control repository
implied by its import path. This can be useful if the source is a local fork
of the original.

The -fix flag instructs get to run the fix tool on the downloaded packages
before resolving dependencies or building the code.

The -insecure flag permits fetching from repositories and resolving
custom domains using insecure schemes such as HTTP. Use with caution.

The -t flag instructs get to also download the packages required to build
the tests for the specified packages.

The -u flag instructs get to use the network to update the named packages
and their dependencies.  By default, get uses the network to check out
missing packages but does not use it to look for updates to existing packages.

Get also accepts build flags to control the installation. See 'go help build'.

实例:
1.在kubernets的编译过程中我们采用如下方式拉取kubernets的源码:

$ go get -d k8s.io/kubernetes
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值