Skip to content

Go 循环依赖检测工具. import cycle not allowed. cyclic dependency detection tool. go-cyclic tool.

Notifications You must be signed in to change notification settings

elza2/go-cyclic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧐🔗 go-cyclic


[ English | 中文 ]

⚡ 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.

# 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.

go install github.com/elza2/go-cyclic@latest

Run command.

go-cyclic run --dir .

Parameters of go-cyclic:
--dir path parameter. Tip: The set directory must be the directory where the go.mod file is located.
--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

Results display

  1. The detection is normal and there is no circular dependency.
Success. Not circular dependence.
  1. Detection failed, there is a circular dependency.
Failed. 1 circular dependence chains were found.

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

About

Go 循环依赖检测工具. import cycle not allowed. cyclic dependency detection tool. go-cyclic tool.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published