go - 强制重新下载/完全清洁环境

标签 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/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 -S go 重新安装 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 命令,它似乎解决了我的问题。

关于go - 强制重新下载/完全清洁环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52707474/

相关文章:

go - 在 Go 中映射 DTO 时减少重复代码的数量

google-app-engine - XP 上的 Golang GAE SDK : Do I have to install it? 还有其他方法可以在 XP 上使用 SDK 吗?

objective-c - 构建 iOS 应用程序后退出代码 1 错误

web-applications - 使用 Gorilla 工具包通过根 URL 提供静态内容

go - 结构上的匿名函数

javascript - 从许多编译为 AMD 模块的 TypeScript 类创建单个 AMD 模块?

ant - 在Cygwin上安装Ant

linux - 虚拟表未生成

android - Android 应用程序的 TFS 自动build设置

string - 判断一个字符是字母还是数字