我遇到一个错误,即go不能正确解决供应商的软件包;在macOS High Sierra 10.13.6上。我将使用github.com/gorilla/mux作为示例包
$ echo $GOPATH
/Users/gregorysims/go
$ go version
go version go1.11 darwin/amd64
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gregorysims/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/gregorysims/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/tb/6c5vksm558q5q4t0fxfscgy80000gp/T/go-build409352678=/tmp/go-build -gno-record-gcc-switches -fno-common"
我要导入的包
import (
...
"github.com/gorilla/mux"
...
)
运行时:
go build -o out main.go
对于供应商中的每个包装,我都会收到以下错误
main.go:6:2: cannot find package "_/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux" in any of:
/usr/local/go/src/_/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/_/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux (from $GOPATH)
该文件夹应该位于
/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux
并且位于目录中。
为什么在下面加上前缀?
/Users/gregorysims/go/src/_
更新
删除本地项目并从远程重新克隆后,我尝试在不下载任何依赖项的情况下进行构建。这具有预期的输出:
main.go:6:2: cannot find package "github.com/gorilla/mux" in any of:
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/github.com/gorilla/mux (from $GOPATH)
仅在运行dep ensure
之后运行build命令之后,才会产生上述错误。
更新2
创建一个空的供应商目录会将输出更改为:
main.go:6:2: cannot find package "github.com/gorilla/mux" in any of:
/Users/gregorysims/go/src/site/user/project/vendor/github.com/gorilla/mux (vendor tree)
/usr/local/go/src/github.com/gorilla/mux (from $GOROOT)
/Users/gregorysims/go/src/github.com/gorilla/mux (from $GOPATH)
更新3
为模拟dep,我叫go get github.com/gorilla/mux
,后跟:
mv $GOPATH/src/github.com/gorilla/mux $GOPATH/src/site/user/project/vendor/github.com/gorilla/mux
这样做之后,问题再次浮出水面。