我是Go的新手,我想我已经搞砸了某个地方的设置。在尝试安装Buffalo框架时,我收到以下错误:
$ buffalo new todo-api --api
Buffalo version v0.9.5
--> go get -u golang.org/x/tools/cmd/goimports
package golang.org/x/tools/cmd/goimports: cannot find package "golang.org/x/tools/cmd/goimports" in any of:
/usr/local/go/src/golang.org/x/tools/cmd/goimports (from $GOROOT)
/home/ankush/go/src/golang.org/x/tools/cmd/goimports (from $GOPATH)
我记得清空$ HOME / go目录,因为我刚刚从1.8升级到1.9,并认为Go会以某种方式自动重新下载并填充它。但它似乎并没有。
那么,src / golang.org目录是否应该在$ GOPATH中?因为我没有在$ GOROOT中找到它并且我遵循了标准设置说明。
有什么建议吗?
==更新1 ==
我的情况下正确设置了GOPATH。这是go env
的输出:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/ankush/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build630744714=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
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"
=== Update2 ===
这是我go get
goimports
的输出结果:
go$ go get -u -v golang.org/x/tools/cmd/goimports
Fetching https://golang.org/x/tools/cmd/goimports?go-get=1
Parsing meta tags from https://golang.org/x/tools/cmd/goimports?go-get=1 (status code 200)
get "golang.org/x/tools/cmd/goimports": found meta tag get.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at https://golang.org/x/tools/cmd/goimports?go-get=1
get "golang.org/x/tools/cmd/goimports": verifying non-authoritative meta tag
Fetching https://golang.org/x/tools?go-get=1
Parsing meta tags from https://golang.org/x/tools?go-get=1 (status code 200)
golang.org/x/tools (download)
package golang.org/x/tools/cmd/goimports: cannot find package "golang.org/x/tools/cmd/goimports" in any of:
/usr/local/go/src/golang.org/x/tools/cmd/goimports (from $GOROOT)
/home/ankush/go/src/golang.org/x/tools/cmd/goimports (from $GOPATH)
答案 0 :(得分:1)
我终于能够解决它了。对于将来被这种情况所困扰的其他人,在我的情况下,它有助于删除相关目录,然后再次安装。这是有帮助的:
$ rm -rf /home/ankush/go/src/golang.org/x/tools
$ go get -u -v golang.org/x/tools/cmd/goimports
我不确定为什么会这样,但是一旦创建了目录,git pull就可能在某种程度上失败了(草率连接?)。