我有个问题
不允许导入周期
它出现在我试图测试我的控制器时。输出如下:
can't load package: import cycle not allowed
package project/controllers/account
imports project/controllers/base
imports project/components/mux
imports project/controllers/account
import cycle not allowed
package project/controllers/account
imports project/controllers/base
imports project/components/mux
imports project/controllers/account
import cycle not allowed
package project/controllers/account
imports project/controllers/base
imports project/components/mux
imports project/controllers/routes
imports project/controllers/base
如何阅读或理解此错误?依赖关系错在哪里?
进口周期的原因已经在上面的回答中提到了。
我在运行build -mod vendor命令时面临内置库的导入周期问题
Ex:
...
...
imports github.com/aws/aws-sdk-go/aws
imports net/http
imports crypto/tls
imports crypto/ecdsa
imports crypto/elliptic
imports crypto/internal/nistec
imports crypto/elliptic: import cycle not allowed
...
...
imports fmt
imports errors
imports internal/reflectlite
imports runtime
imports internal/abi
imports internal/goarch
imports bytes
imports errors: import cycle not allowed
这个问题通过卸载golang并重新安装来解决。我想我之前没有正确安装戈朗。谢谢你在https://bytemeta.vip/repo/fyne-io/fyne/issues/3089上的提示。我不能把功劳给那个人,但要在这里提一下。谢谢。
我刚刚遇到了这个。您可以使用包名本身从同一个包中访问一个方法/类型。
下面是一个例子来说明我的意思:
在foo.go:
// foo.go
package foo
func Foo() {...}
在foo_test.go:
// foo_test.go
package foo
// try to access Foo()
foo.Foo() // WRONG <== This was the issue. You are already in package foo, there is no need to use foo.Foo() to access Foo()
Foo() // CORRECT
循环依赖的另一个常见原因显示在这个答案中。
与JavaScript不同,Go对循环依赖的容忍度很低,这是好事也是坏事。