[实践OK]go-cyclic 循环依赖解决工具,解决import cycle not allowed。

jackxiang 2023-7-7 09:58 | |
import cycle not allowed
而且如果项目很大的时候,一个包下面有很多 .go 文件,只提示包与包的循环引用(如上图),是很难定位到哪个 .go 文件和哪个 .go 文件直接进行了循环引用,难以排查。

go-cyclic run --dir  ~/go_learning/src/pdfwatcher.src.cctv.cn
Failed. 1 circular dependence chains were found.

┌---→  /Users/jackXiang/go_learning/src/pdfwatcher.src.cctv.cn/Requests/Request.go
┆                                       ↓
└---     /Users/jackXiang/go_learning/src/pdfwatcher.src.cctv.cn/Loger/Loger.go


安装:
go install github.com/elza2/go-cyclic@latest
go: downloading github.com/elza2/go-cyclic v1.1.0
go: downloading github.com/fatih/color v1.15.0
go: downloading golang.org/x/mod v0.8.0
go: downloading github.com/urfave/cli/v2 v2.24.4
go: downloading github.com/mattn/go-isatty v0.0.17
go: downloading github.com/mattn/go-colorable v0.1.13
go: downloading golang.org/x/sys v0.6.0
go: downloading github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.2
go: downloading github.com/russross/blackfriday/v2 v2.1.0



来自:https://link.zhihu.com/?target=https%3A//github.com/elza2/go-cyclic

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/11915/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!

评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]