MCPcopy Index your code
hub / github.com/elza2/go-cyclic

github.com/elza2/go-cyclic @v1.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.0 ↗ · + Follow
57 symbols 117 edges 31 files 2 documented · 4%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

🧐🔗 go-cyclic


[ English | 中文 ]

⚡ Go的循环依赖检测工具 ⚡

🤔 什么是 go-cyclic

在 Go 应用程序的开发过程中,包与包之间的循环依赖是一个常见的问题,这类情况通常会导致编译错误,具体表现为import cycle not allowed的提示。当项目规模膨胀,依赖关系错综复杂时,识别并解决循环引用的问题就变得更加具有挑战性,往往会耗费开发者大量的时间和精力。

正是鉴于这一痛点,go-cyclic工具应运而生,它的设计初衷是为了高效且精准地帮助开发者定位项目中的循环引用问题。通过智能化的分析,go-cyclic能够迅速揭示循环依赖的具体位置,从而极大地简化了排查过程,保证了项目的健康与可维护性,是优化大型项目结构、提升开发效率的得力助手。

以下是会出现循环依赖的示例。

# a.go                       # b.go
package a                    package b

import "b"                   import "a"

type A struct {              type B struct {
  B *b.B                       A *a.A
}                            }

快速开始

安装命令

go install github.com/elza2/go-cyclic

运行命令

go-cyclic run --dir .

go-cyclic 的参数:

--dir 路径参数。提示:设置的目录要为 go.mod 文件所在的目录。

--filter (可选) 过滤参数。提示:过滤匹配的文件,不参与循环检测。多个条件使用英文逗号隔开,支持表达式,例如 --filter *_test.go,a_test.go

结果展示

  1. 检测正常,无循环依赖。
Success. Not circular dependence.
  1. 检测失败,存在循环依赖。
Failed. 1 circular dependence chains were found.

┌---→    app.go
┆          ↓
┆       routes.go
┆          ↓
└---    handler.go

Core symbols most depended-on inside this repo

Do
called by 7
core/detector.go
fillBlank
called by 4
core/detector.go
NewCyclicDetector
called by 1
core/detector.go
Parse
called by 1
core/detector.go
ParseFilters
called by 1
core/detector.go
ParseResolvers
called by 1
core/detector.go
ParseNodeResolver
called by 1
core/detector.go
GetNodePathName
called by 1
core/detector.go

Shape

Function 26
Struct 23
Method 8

Languages

Go100%

Modules by API surface

core/detector.go16 symbols
core/detector_test.go6 symbols
example/three_cyclic2/a/a.go2 symbols
example/three_cyclic/a/a.go2 symbols
example/simple_cyclic3/a/a.go2 symbols
example/simple_cyclic2/a/a1.go2 symbols
example/simple_cyclic/a/a.go2 symbols
example/multiple_cyclic/a/a.go2 symbols
main.go1 symbols
example/three_cyclic2/test_test.go1 symbols
example/three_cyclic2/c/c.go1 symbols
example/three_cyclic2/b/b.go1 symbols

For agents

$ claude mcp add go-cyclic \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact