英文:
Why doesn't go locate my vendored library?
问题
package vpc_app/unit_test.go:
import (
"github.com/my-org/my-library/http"
)
...
package github.com/my-org/my-library/http/http.go:
package http
...
文件结构:
$ tree
.
├── glide.lock
├── glide.yaml
├── unit
│ └── modules
│ └── vpc
│ └── vpc-app
│ └── unit_test.go
└── vendor
└── github.com
└── my-org
└── my-library
├── http
│ └── http.go
问题:
当我运行 go test ./...
时,我得到以下错误:
vendor/github.com/my-org/my-library/url_checker.go:7:2: cannot find package "github.com/my-org/my-library/http" in any of:
/usr/local/go/src/github.com/my-org/my-library/http (from $GOROOT)
/Users/josh/go/src/github.com/my-org/my-library/http (from $GOPATH)
问题:
我正在使用 go 1.6,但它似乎没有查找我的 vendor 目录来找到该包。有任何关于这个问题的想法吗?
更新 #1:
根据您的要求,这是我的 go env
输出:
OARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/josh/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/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"
英文:
package vpc_app/unit_test.go:
import (
"github.com/my-org/my-library/http"
)
...
package github.com/my-org/my-library/http/http.go:
package http
...
File Structure:
$ tree
tree
.
├── glide.lock
├── glide.yaml
├── unit
│   └── modules
│   └── vpc
│   └── vpc-app
│   └── unit_test.go
└── vendor
└── github.com
└── my-org
└── my-library
├── http
│   └── http.go
Problem:
When I run go test ./...
I get this error:
vendor/github.com/my-org/my-library/url_checker.go:7:2: cannot find package "github.com/my-org/my-library/http" in any of:
/usr/local/go/src/github.com/my-org/my-library/http (from $GOROOT)
/Users/josh/go/src/github.com/my-org/my-library/http (from $GOPATH)
Question:
I'm using go 1.6, but it doesn't seem to look in my vendor directory to find the package. Any ideas on why that might be?
Update #1:
As requested, here's my go env
output:
OARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/josh/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/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"
答案1
得分: 1
我的存储库没有位于GOPATH
中。将其移动到$GOPATH/src/github.com/my-org/my-library
解决了问题。
英文:
My repo wasn't located in the GOPATH
. Moving it to $GOPATH/src/github.com/my-org/my-library
did the trick.
答案2
得分: 0
那个错误来自于vendor/github.com/my-org/my-library/url_checker.go
,它位于你的vendor文件夹中。
看起来它确实找到了vendor文件夹,但问题是由于vendor/github.com/my-org/my-library/url_checker.go
中第7行的导入语句引起的。
正在调查是否存在与vendor文件夹的递归依赖关系有关的问题。
为了明确起见,你能提供go env
的输出吗?
英文:
That error is originating from vendor/github.com/my-org/my-library/url_checker.go
which is in your vendor folder.
It looks like it is finding the vendor folder, but the issue is due to an import statement in vendor/github.com/my-org/my-library/url_checker.go
on line 7
Investigating to see if there is an issue with recursive dependencies with vendor folders.
Just to be clear can you provide the output of go env
?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论