在运行 Golang 示例时出现 “import cycle not allowed” 的错误。

huangapple go评论81阅读模式
英文:

"import cycle not allowed" while running test in golang example

问题

我正在尝试为我的 Golang 函数设置测试,但在控制台运行 go test ... 时遇到以下错误:

import cycle not allowed package runtime
imports unsafe
imports runtime

我以为是我的问题,所以我克隆了golang 示例项目并运行了 go test reverse_test.go,但是得到了相同的错误。
我的 GOPATHGOROOT 环境变量的值都设置为 C:\go,这是我安装 Go 的位置。
我使用的是 Windows 8.1 64 位机器。

有什么想法是出了什么问题吗?

英文:

I'm trying to setup tests for my functions in golang, but getting the following error while running go test ... from the console:

> import cycle not allowed package runtime
> imports unsafe
> imports runtime

Thinking that it was me I cloned the golang example project and ran go test reverse_test.go, but getting the same error.
Both my GOPATH and GOROOT environment values are set to C:\go, where I installed Go.
I'm on a Windows 8.1, 64bit machine.

Any ideas what's wrong?

答案1

得分: 3

确保在将GOPATH设置为正确路径后执行"go get github.com/golang/example/hello"(如github.com/golang/example中所述)。

请参阅" 如何编写Go代码 ":

GOPATH环境变量指定工作区的位置。在开发Go代码时,这可能是您唯一需要设置的环境变量。

您应该在$GOPATH/src中看到您的github/golang/example

英文:

Make sure to do a "go get github.com/golang/example/hello" (as mentioned in github.com/golang/example) once your GOPATH is set to a proper path.

See "How to Write Go Code":

> The GOPATH environment variable specifies the location of your workspace. It is likely the only environment variable you'll need to set when developing Go code.

You should see your github/golang/example inside $GOPATH/src

huangapple
  • 本文由 发表于 2014年12月30日 03:58:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/27695186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定