gpt4 book ai didi

GO (Golang) vendor 实验在 mac osx 上失败

转载 作者:IT王子 更新时间:2023-10-29 01:42:09 27 4
gpt4 key购买 nike

在 osx 上使用 go 1.6.2 进行 go vendor 实验时遇到一些问题。

这是我的目录结构:

/project
/application
main.go
other.go
/vendor
/github.com
/vendor_name
/package_name

我将我的 GOPATH 设置为 /Users/me/project/application然而,当我尝试运行任何 go 工具(例如构建)时,它似乎在寻找 application/src 而不是 application/vendor,得到很多这样的东西:

main.go:15:2: cannot find package "github.com/facebookgo/grace/gracehttp" in any of:
/usr/local/Cellar/go/1.6.2/libexec/src/github.com/facebookgo/grace/gracehttp (from $GOROOT)
/Users/me/project/application/src/github.com/facebookgo/grace/gracehttp (from $GOPATH)

正如您所见,默认情况下,go env 输出 vendor 实验处于启用状态,因为它似乎不起作用:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/me/project/application"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.6.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.6.2/libexec/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

现在,funkiness 的来源可能是以前安装 go 的后遗症。随着时间的推移,我安装了各种版本的 go,一些通过 gvm(go 版本管理器),一些通过 homebrew。所以我卸载了 gvm 和它安装的 go 版本,也卸载了 go with homebrew 并使用 homebrew 重新安装了 1.6.2。

go版本输出:

go version go1.6.2 darwin/amd64

哪个Go:

/usr/local/bin/go

这里可能出了什么问题,或者我可能只是误解了 vendor 应该如何运作?

附言如果您需要更多信息,请告诉我,很乐意提供

最佳答案

it seems to be looking in application/src

是的,go 会在 $GOPATH/src 中查找您的源代码 vendor 源文件夹。

一切都应该在$GOPATH/src

vendor folder 只能通过以“vendor”的父级为根的目录树中的代码导入。
但它是你源代码的一部分,因此应该在 $GOPATH/src 下。

关于GO (Golang) vendor 实验在 mac osx 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37253780/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com