Golang easily resolves circular dependencies

If you check the code with go vet, or when compiling the code, it shows a circular dependency error, it looks like this:

package code/app/user/service
        imports code/app/system/service
        imports code/app/user/service: import cycle not allowed

If you don't have a similar error report, you only get a package name and code/app/user/serviceyou can use the command to make him display the above error report.

go list code/app/user/service

After getting an error, you need to search for code/app/user/servicethe line of code that imports this package in the code. The most important thing is the search scope, which is the directory of code/app/system/servicethe package, that is service.

You will search for the line of code that imports the package, and then search where the package is used in the file, modify the code implementation, and no longer import this package, and the problem will be solved.

postscript

After I encountered this problem, I referred to many articles, and they all recommended some visualization tools for displaying package dependencies. I think it is not as convenient as the tools that come with Go.

Guess you like

Origin blog.csdn.net/Deng_Xian_Sheng/article/details/129435409