Go工具无法找到二进制文件。go工具:没有名为”vet”的工具。

huangapple go评论97阅读模式
英文:

Go tool unable to find binary. go tool: no such tool "vet"

问题

我正在一个 Docker 容器中运行 Golang,但是 go tool 找不到 vet。你能给我一些关于如何调试这个问题的思路吗?

你使用了 1.5 版本的 Dockerfile 作为模板。链接在这里:https://github.com/docker-library/golang/blob/51d6eacd41fe80d41105142b9ad32f575082970f/1.5/Dockerfile

ENV GOLANG_VERSION 1.5.1
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA1 46eecd290d8803887dec718c691cc243f2175fe0

RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
	&& echo "$GOLANG_DOWNLOAD_SHA1  golang.tar.gz" | sha1sum -c - \
	&& tar -C /usr/local -xzf golang.tar.gz \
	&& rm golang.tar.gz

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

然而,当我使用以下命令安装 govet:

go get golang.org/x/tools/cmd/vet

然后尝试运行:

bash-4.3# go tool vet
go tool: no such tool "vet"

我已经设置了以下 Go 环境:

$PATH 包括 $GOPATH/bin /usr/lib/go/bin:/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

bash# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
bash# ls $GOPATH/bin
fgt               go-junit-report   godep             golint            mt-content-blogs  vet   
bash# ls $GOROOT/bin/
go     gofmt

问题的关键在于 go tool 列出的工具中没有 vet,即使我使用 go get golang.org/x/tools/cmd/vet 安装了它。

bash# go tool
addr2line
api
asm
cgo
compile
dist
doc
fix
link
nm
objdump
pack
pprof
trace
yacc

希望这些信息对你有帮助。

英文:

I'm running golang in a docker container. And 'go tool' is unable to find 'vet'. Could you give me ideas on how to debug this?

I've used the Dockerfile for 1.5 as a template. https://github.com/docker-library/golang/blob/51d6eacd41fe80d41105142b9ad32f575082970f/1.5/Dockerfile

ENV GOLANG_VERSION 1.5.1
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-        amd64.tar.gz
ENV GOLANG_DOWNLOAD_SHA1 46eecd290d8803887dec718c691cc243f2175fe0

RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \
&& echo "$GOLANG_DOWNLOAD_SHA1  golang.tar.gz" | sha1sum -c - \
&& tar -C /usr/local -xzf golang.tar.gz \
&& rm golang.tar.gz

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

However, when I install govet with

go get golang.org/x/tools/cmd/vet 

and try

bash-4.3# go tool vet
go tool: no such tool "vet"

I have the following go environment set up:

$PATH includes $GOPATH/bin /usr/lib/go/bin:/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

bash# go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
bash# ls $GOPATH/bin
fgt               go-junit-report   godep             golint            mt-content-blogs  vet   
bash# ls $GOROOT/bin/
go     gofmt

The crux of the issue is that go tools does not list vet, even after installing it with go get golang.org/x/tools/cmd/vet

bash# go tool
addr2line
api
asm
cgo
compile
dist
doc
fix
link
nm
objdump
pack
pprof
trace
yacc

答案1

得分: 1

警告:从Go 1.12(2019年2月,3.5年后)开始,go tool vet将不再可用。只有go vet可用。

请参阅go 1.12发布说明

go vet命令已被重写,作为一系列不同源代码分析工具的基础。有关详细信息,请参阅golang.org/x/tools/go/analysis包。

副作用是不再支持go tool vet。使用go tool vet的外部工具必须更改为使用go vet。使用go vet而不是go tool vet应该适用于所有支持的Go版本。

作为此更改的一部分,实验性的-shadow选项在go vet中不再可用。现在可以使用以下方式检查变量遮蔽:

go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
go vet -vettool=$(which shadow)
英文:

Warning: starting Go 1.12 (February 2019, 3.5 years later), go tool vet won't be available at all. Only go vet.

See go 1.12 release notes:

> The go vet command has been rewritten to serve as the base for a range of different source code analysis tools. See the golang.org/x/tools/go/analysis package for details.

> A side-effect is that go tool vet is no longer supported.
External tools that use go tool vet must be changed to use go vet.
Using go vet instead of go tool vet should work with all supported versions of Go.

> As part of this change, the experimental -shadow option is no longer available with go vet.
Checking for variable shadowing may now be done using:

go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
go vet -vettool=$(which shadow)

答案2

得分: -1

找到了问题所在。看起来我在使用的基础Docker镜像上忘记安装Go工具。

RUN apk --update-cache --allow-untrusted \
--repository http://dl-3.alpinelinux.org/alpine/edge/community/ \
--arch=x86_64 add \
go=${GOLANG_VERSION}-r3 \
go-tools=${GOLANG_VERSION}-r3 \
git \
&& rm -rf /var/cache/apk/* \
&& mkdir -p /go/src /go/bin \
&& chmod -R 777 /go
英文:

Figured out the issue. It appears that I had missed installing go tools on the base docker image that I was using.

RUN apk --update-cache --allow-untrusted \
--repository http://dl-3.alpinelinux.org/alpine/edge/community/ \
--arch=x86_64 add \
go=${GOLANG_VERSION}-r3 \
go-tools=${GOLANG_VERSION}-r3 \
git \
&& rm -rf /var/cache/apk/* \
&& mkdir -p /go/src /go/bin \
&& chmod -R 777 /go

huangapple
  • 本文由 发表于 2015年10月27日 20:53:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/33368510.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定