Skip to content

Commit

Permalink
EL-003(feat): go version upgrade. (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: yuanyou <yuanyou@kezaihui.com>
  • Loading branch information
elza2 and yuanyou authored May 25, 2024
1 parent 8936a99 commit 9d8ac51
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 33 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# make cyclic
cyclic:
go install github.com/elza2/go-cyclic@latest
go-cyclic run --dir . filter *_test.go
54 changes: 35 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
# go-cyclic
# 🧐🔗 go-cyclic
<hr/>

<h4> Go 循环依赖检测工具 </h4>
[ English | [中文](README_zh.md) ]

快速开始
===============
⚡ Circular dependency detection tool for Go ⚡

## 🤔 What is go-cyclic?
In the development process of Go applications, cyclic dependencies between packages are a common problem. This kind of situation usually leads to compilation errors. Specifically, execute the prompt of `import cycle not allowed`. When the project scale expands and dependencies become complex, identifying and solving circular reference problems becomes more challenging, often resulting in a lot of time and effort.

It is in view of this pain point that the `go-cyclic` tool came into being. It was originally designed to help developers locate circular reference problems in projects efficiently and accurately. Through intelligent analysis, `go-cyclic` can quickly reveal the specific location of cyclic dependencies, thus greatly simplifying the troubleshooting process and ensuring the health and maintainability of the project. It is a powerful assistant for optimizing the structure of large projects and improving development efficiency. .

The following are examples of where circular dependencies can occur.
```bash
go install github.com/elza2/go-cyclic@latest
# path 路径要设置为 go.mod 文件所在的路径.
# filter 过滤匹配的文件, 多个条件使用逗号隔开(,)
go-cyclic run --dir .path [--filter *_test.go]
# a.go # b.go
package a package b

import "b" import "a"

type A struct { type B struct {
B *b.B A *a.A
} }
```
运行测试
===============
## Quick Start
Install command.
```bash
go install github.com/elza2/go-cyclic
```
Run command.
```bash
git clone https://github.com/elza2/go-cyclic.git
# path 路径要设置为 go.mod 文件所在的路径.
go run ./main.go run --dir .path [--filter *_test.go]
go-cyclic run --dir .
```
Parameters of go-cyclic:<br/>
`--dir` path parameter. Tip: The set directory must be the directory where the go.mod file is located.<br/>
`--filter` (optional) filter parameters. Tip: Filter matching files and do not participate in loop detection. Multiple conditions are separated by commas and expressions are supported, such as `--filter *_test.go,a_test.go`<br/>
## Results display
1. The detection is normal and there is no circular dependency.
运行结果
===============
```bash
# success output.
Success. Not circular dependence.
```
# failed output.
2. Detection failed, there is a circular dependency.
```bash
Failed. 1 circular dependence chains were found.

┌---→ app.go
Expand All @@ -34,5 +52,3 @@ Failed. 1 circular dependence chains were found.
┆ ↓
└--- handler.go
```


55 changes: 55 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 🧐🔗 go-cyclic
<hr/>

[ [English](README.md) | 中文 ]

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

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

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

以下是会出现循环依赖的示例。
```bash
# a.go # b.go
package a package b

import "b" import "a"

type A struct { type B struct {
B *b.B A *a.A
} }
```
##快速开始
安装命令
```bash
go install github.com/elza2/go-cyclic
```
运行命令
```bash
go-cyclic run --dir .
```
go-cyclic 的参数:<br/>
`--dir` 路径参数。提示:设置的目录要为 go.mod 文件所在的目录。<br/>
`--filter` (可选) 过滤参数。提示:过滤匹配的文件,不参与循环检测。多个条件使用英文逗号隔开,支持表达式,例如 `--filter *_test.go,a_test.go`
##结果展示
1. 检测正常,无循环依赖。
```bash
Success. Not circular dependence.
```
2. 检测失败,存在循环依赖。
```bash
Failed. 1 circular dependence chains were found.

┌---→ app.go
┆ ↓
┆ routes.go
┆ ↓
└--- handler.go
```
3 changes: 2 additions & 1 deletion core/detector_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package core_test

import (
"go-cyclic/core"
"testing"

"github.com/elza2/go-cyclic/core"
)

func TestSimpleCyclic(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion example/multiple_cyclic/test_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package simple_cyclic_test

import (
"go-cyclic/example/multiple_cyclic/a"
"testing"

"go-cyclic/example/multiple_cyclic/a"
)

func TestCyclic(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion example/simple_cyclic2/test_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package simple_cyclic_test

import (
"go-cyclic/example/simple_cyclic2/a"
"testing"

"go-cyclic/example/simple_cyclic2/a"
)

func TestCyclic(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion example/simple_cyclic3/test_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package simple_cyclic_test

import (
"go-cyclic/example/simple_cyclic3/a"
"testing"

"go-cyclic/example/simple_cyclic3/a"
)

func TestCyclic(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion example/three_cyclic/test_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package simple_cyclic_test

import (
"go-cyclic/example/three_cyclic/a"
"testing"

"go-cyclic/example/three_cyclic/a"
)

func TestCyclic(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion example/three_cyclic2/test_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package simple_cyclic_test

import (
"go-cyclic/example/three_cyclic2/a"
"testing"

"go-cyclic/example/three_cyclic2/a"
)

func TestCyclic(t *testing.T) {
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module github.com/elza2/go-cyclic

go 1.18
go 1.21.0

require (
github.com/fatih/color v1.15.0
github.com/urfave/cli/v2 v2.24.4
golang.org/x/mod v0.8.0
github.com/fatih/color v1.17.0
github.com/urfave/cli/v2 v2.27.2
golang.org/x/mod v0.17.0
)

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sys v0.6.0 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/sys v0.20.0 // indirect
)
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/urfave/cli/v2 v2.24.4 h1:0gyJJEBYtCV87zI/x2nZCPyDxD51K6xM8SkwjHFCNEU=
github.com/urfave/cli/v2 v2.24.4/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 comments on commit 9d8ac51

Please sign in to comment.