2

我正在使用 Go 版本 1.8,Glide 用于包依赖,我的项目结构是

/Users/myName/go
    bin/
    pkg/
    src/
        main.go
        vendor/
            github.com/
            gaoling.org/

完成后我所有的软件包都安装在供应商文件夹中glide install,当我这样做时go build出现以下错误

main.go:7:2: cannot find package "github.com/julienschmidt/httprouter" in any of:
/usr/local/Cellar/go/1.8.1/libexec/src/github.com/julienschmidt/httprouter (from $GOROOT)
/Users/myName/go/src/github.com/julienschmidt/httprouter (from $GOPATH)

并且go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/myName/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.1/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/st/28pcgmmj1sb84ch1n_76g_k00000gn/T/go-build454728554=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
4

1 回答 1

0

glide 以旧方式工作,因此您需要将代码移动到文件夹/Users/myName/go/src/github.com/projectName并运行 glide。你的 main.go 和 vendor 文件应该在你的 projectName 文件夹下。

于 2020-09-27T18:38:23.587 回答