Go 强制卸载/完全清洁环境

Go 强制卸载/完全清洁环境,go,build,Go,Build,首先,我没有go方面的经验,我只是尝试从github构建一个项目 我的问题是:当我在克隆的go项目中使用go build时,我会遇到如下一系列错误: transform.go:28:2: cannot find package "github.com/disintegration/imaging" in any of: /usr/lib/go/src/github.com/disintegration/imaging (from $GOROOT) /home/ma

首先,我没有go方面的经验,我只是尝试从github构建一个项目

我的问题是:当我在克隆的go项目中使用
go build
时,我会遇到如下一系列错误:

transform.go:28:2: cannot find package "github.com/disintegration/imaging" in any of:
        /usr/lib/go/src/github.com/disintegration/imaging (from $GOROOT)
        /home/marcus/go/src/github.com/disintegration/imaging (from $GOPATH)
imageproxy.go:34:2: cannot find package "github.com/gregjones/httpcache" in any of:
        /usr/lib/go/src/github.com/gregjones/httpcache (from $GOROOT)
        /home/marcus/go/src/github.com/gregjones/httpcache (from $GOPATH)
transform.go:29:2: cannot find package "github.com/muesli/smartcrop" in any of:
        /usr/lib/go/src/github.com/muesli/smartcrop (from $GOROOT)
        /home/marcus/go/src/github.com/muesli/smartcrop (from $GOPATH)
发生的事情:我破坏了一切,因为我开始删除随机目录,希望修复我遇到的另一个问题。我删除了我的
~/go
目录和
~/.cache/go build
目录

我的尝试:到目前为止,除了导致问题的删除之外,我还尝试了
go clean-cache-modcache
;添加
-r
标志会产生与上述相同的错误
go build-a
也会产生相同的错误。我也尝试过用pacman-sGo重新安装go

我的
go-env
是:

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/marcus/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/marcus/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build315222728=/tmp/go-build -gno-record-gcc-switches"

我知道我做了一些意想不到的事情,但我很惊讶Go在这里挣扎。我怎样才能让Go意识到软件包不存在,它应该通过下载来解决这个问题?或者,我如何清理我的环境以移除仍然存在的任何工件,这些工件使Go认为包应该仍然存在

在阅读回复评论后,我偶然发现了
go mod verify
命令,它似乎解决了我的问题

您必须明确地
获取它所说的每个软件包不在您的系统上(例如
获取github.com/dissection/imaging
)。它不会尝试自动检索它们。从安全角度来看,如果它只是从互联网上随意下载代码并编译,那将是非常糟糕的。我会尝试一下,但我仍然很好奇,为什么go现在没有自动执行呢?当我第一次克隆项目并运行
go build
时,它开始下载所有包。还有什么工件阻止go获取它们?因为我可以创建一个合法的库,让成千上万的人使用它,然后在钩住人后决定恶意,在任何源文件中添加一行以导入恶意的外部repo,然后它会自动检索、编译它,然后人们就会运行它。我敢肯定你记错了,因为我无法想象它会自动下载第三方代码。也许因为我是新手,我误解了输出,但这是第一次发生的事情: