如果我拼写依赖项错误,Go 只会在我的供应商目录中查找。我使用 glide 添加供应商。
此导入拼写正确
package goserver
import (
"net/http"
"fmt"
"github.com/gorilla/mux"
)
正确拼写 dep 的结果。Go 在 2 个目录中查找,而不是在供应商树目录中查找
myhost:goserver myuser$ go build main.go
go-server/routers.go:6:2: cannot find package "_/Users/myuser/go/src/goserver/vendor/github.com/gorilla/mux" in any of:
/usr/local/Cellar/go/1.9/libexec/src/_/Users/myuser/go/src/goserver/vendor/github.com/gorilla/mux (from $GOROOT)
/Users/myuser/go/src/_/Users/myuser/go/src/goserver/vendor/github.com/gorilla/mux (from $GOPATH)
进口拼写错误
package goserver
import (
"net/http"
"fmt"
"githubwwwww.com/gorilla/mux"
)
dep 拼写错误的结果。Go 查看 3 个目录并查看 vendor 目录
myhost:goserver myuser$ go build main.go
go-server/routers.go:6:2: cannot find package "githubwwwww.com/gorilla/mux" in any of:
/Users/myuser/go/src/goserver/vendor/githubwwwww.com/gorilla/mux (vendor tree)
/usr/local/Cellar/go/1.9/libexec/src/githubwwwww.com/gorilla/mux (from $GOROOT)
/Users/myuser/go/src/githubwwwww.com/gorilla/mux (from $GOPATH)
证明 gorrila/mux 存在
myhost:goserver myuser$ ls /Users/myuser/go/src/goserver/vendor/github.com/gorilla/mux/
LICENSE bench_test.go context_gorilla_test.go context_native_test.go mux.go old_test.go route.go
README.md context_gorilla.go context_native.go doc.go mux_test.go regexp.go
去环境结果
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/myuser/go/"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ty/vksmqd9x38vclbmpbnvnqwwh0000gp/T/go-build089246630=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"