找出构建二进制文件的版本吗? [英] Find out the version of Go a Binary was built with?

查看:62
本文介绍了找出构建二进制文件的版本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉您二进制文件的构建版本?

Is there a way to tell what go version a binary was built with?

我的工作站上有多个go实例,因此我想验证是否使用了正确的实例.

I have multiple go instances on my workstation, so I want to verify that the correct one was used.

推荐答案

使用 runtime.Version()在运行时找出二进制文件的哪个版本的Go:

Use runtime.Version() at runtime to figure out what version of Go your binary was built with:

func Version() string

Version返回Go树的版本字符串.它可以是一个序列编号,或者在可能的情况下使用类似"release.2010-03-04"的发行标签.一种尾随+表示该树当时具有局部修改的版本.

Version returns the Go tree's version string. It is either a sequence number or, when possible, a release tag like "release.2010-03-04". A trailing + indicates that the tree had local modifications at the time of the build.

对于现有的二进制文件,请使用 go version 命令:

For existing binaries, use the go version command:

用法:转到版本[-m] [-v] [文件...]

版本会打印Go可执行文件的构建信息.

Version prints the build information for Go executables.

Go版本报告用于构建每个命名版本的Go版本可执行文件.

Go version reports the Go version used to build each of the named executable files.

如果在命令行上未命名文件,则go version会自行打印版本信息.

If no files are named on the command line, go version prints its own version information.

如果目录已命名,则go version递归地遍历该目录,寻找公认的Go二进制文件并报告其版本.默认情况下,go版本不会报告找到的无法识别的文件在目录扫描期间. -v 标志使它报告无法识别的文件.

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.

-m 标志导致go版本打印每个可执行文件的嵌入式模块版本信息(如果有).在输出中,模块信息由版本行之后的多行组成,每行由前导制表符缩进.

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.

这篇关于找出构建二进制文件的版本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆