[Go] Golang version命令的高级用法
Contents
Golang version命令的高级用法
go version命令常用来查看Go版本和系统架构信息
查看Go版本信息
> go version
go version go1.14 darwin/amd64
用法
使用help子命令查看任意命令的帮助
> go help version
usage: go version [-m] [-v] [file ...]
Version prints the build information for Go executables.
Go version reports the Go version used to build each of the named
executable files.
If no files are named on the command line, go version prints its own
version information.
If a directory is named, go version walks that directory, recursively,
looking for recognized Go binaries and reporting their versions.
By default, go version does not report unrecognized files found
during a directory scan. The -v flag causes it to report unrecognized files.
The -m flag causes go version to print each executable's embedded
module version information, when available. In the output, the module
information consists of multiple lines following the version line, each
indented by a leading tab character.
See also: go doc runtime/debug.BuildInfo.
它可以接受多个文件,用于打印这些文件的构建版本信息。
查看任意文件
查看执行文件版本构建信息,在$GOBIN目录下查看,或者使用绝对路径
> go version goimports
goimports: go1.14
打印出goimports这个执行文件是使用go1.14版本构建
查看多个文件
> go version goimports gocode
goimports: go1.14
gocode: go1.14
查看指定目录下所有文件
> go version $GOBIN
goimports: go1.14
gocode: go1.14
查看go mod信息
通过-m选项查看可执行文件的go mod信息
> go version -m gocode
gocode: go1.14
path github.com/mdempsky/gocode
mod github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f h1:ee+twVCignaZjt7jpbMSLxAeTN/Nfq9W/nm91E7QO1A=
dep golang.org/x/tools v0.0.0-20191018212557-ed542cd5b28a h1:UuQ+70Pi/ZdWHuP4v457pkXeOynTdgd/4enxeIO/98k=
打印出项目路径path和mod信息,以及依赖dep库,和它们对应的版本信息