简体   繁体   English

Go工具无法找到二进制文件。 去工具:没有这样的工具“兽医”

[英]Go tool unable to find binary. go tool: no such tool “vet”

I'm running golang in a docker container. 我在docker容器中运行golang。 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. 我使用Dockerfile 1.5作为模板。 https://github.com/docker-library/golang/blob/51d6eacd41fe80d41105142b9ad32f575082970f/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

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: 我设置了以下go环境:

$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 问题的症结在于,即使使用go get golang.org/x/tools/cmd/vet进行安装,go工具也不会列出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

Warning: starting Go 1.12 (February 2019, 3.5 years later), go tool vet won't be available at all. 警告:从Go 1.12开始(2019年2月,3.5年后), go tool vet将完全不可用。 Only go vet . 只做go vet

See go 1.12 release notes : 请参阅go 1.12发行说明

The go vet command has been rewritten to serve as the base for a range of different source code analysis tools. go vet命令已被重写,可以用作各种不同源代码分析工具的基础。 See the golang.org/x/tools/go/analysis package for details. 有关详细信息,请参阅golang.org/x/tools/go/analysis软件包。

A side-effect is that go tool vet is no longer supported . 副作用是不再支持go tool vet
External tools that use go tool vet must be changed to use go vet . 必须将使用go tool vet外部工具更改为使用go vet
Using go vet instead of go tool vet should work with all supported versions of Go. 使用go vet代替go tool vet应该可以与所有受支持的Go版本一起使用。

As part of this change, the experimental -shadow option is no longer available with go vet . 作为此更改的一部分, go vet不再提供实验性-shadow选项。
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)

Figured out the issue. 找出问题。 It appears that I had missed installing go tools on the base docker image that I was using. 看来我错过了在使用的基本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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM