Import cycle not allowed

后端 未结 4 954
误落风尘
误落风尘 2020-12-22 20:06

I have a problem with

import cycle not allowed

It appears, when I am trying to test my controller. As output I\'ve got

4条回答
  •  忘掉有多难
    2020-12-22 20:51

    I just encountered this. You may be accessing a method/type from within the same package using the package name itself.

    Here is an example to illustrate what I mean:

    In foo.go:

    // foo.go
    package foo
    
    func Foo() {...}
    

    In 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
    

提交回复
热议问题