一尘不染

不允许导入周期

go

我有一个问题

不允许导入周期

当我尝试测试控制器时,它会出现。作为输出,我有

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

有人可以告诉我如何阅读或理解此错误吗?依赖关系哪里出问题了?


阅读 291

收藏
2020-07-02

共1个答案

一尘不染

这是第一个导入周期问题的说明。

                  project/controllers/account
                     ^                    \    
                    /                      \
                   /                        \ 
                  /                         \/
         project/components/mux <--- project/controllers/base

你可以用我的坏ASCII图表看是要创建一个导入周期时project/components/mux进口project/controllers/account。由于Go不支持循环依赖关系,因此您会import cycle not allowed在编译期间收到错误消息。

2020-07-02