Home > Backend Development > Golang > Let's talk about the cyclic dependency detection tool (go-cyclic) in Go

Let's talk about the cyclic dependency detection tool (go-cyclic) in Go

藏色散人
Release: 2022-12-12 20:21:44
forward
6543 people have browsed it

This article will introduce you to the relevant knowledge about Golang and talk about a cyclic dependency detection tool (go-cyclic) in open source Go. I hope it will be helpful to you.

go-cyclic cyclic dependency resolution tool

Problem description

As a Go developer , we often encounter package circular dependency problems in large projects.
If there is a circular dependency in Golang, an exception will be thrown during compilation.

When do circular dependencies occur?

If there are two packages: package a and package b. When package a depends on package b, and package b depends on package a, a circular dependency will occur. The real situation may be more complicated. For example, if package a depends on package b, package b depends on package c, and package c depends on package a, a cycle is formed.
Lets talk about the cyclic dependency detection tool (go-cyclic) in GoLets talk about the cyclic dependency detection tool (go-cyclic) in Go

import cycle not allowed
Copy after login

And if the project is very large, there are many .go files under a package, and only circular references between packages are prompted (as shown above), which is difficult to locate. Which .go file and which .go file are directly referenced in a circular manner, which is difficult to check.

go-cyclic simple usage

Github address: github.com/elza2/go-cyclic (Welcome to submit PRs)

go-cyclic can be used to check whether there are cyclic dependencies in the project and locate specific .go files. Helps quickly locate loop problems.

Quick Start

go install github.com/elza2/go-cyclic@latest
# path 路径要设置为 go.mod 文件所在的路径.go-cyclic gocyclic --dir .path
Copy after login
rrree

Lets talk about the cyclic dependency detection tool (go-cyclic) in Go

The above is the detailed content of Let's talk about the cyclic dependency detection tool (go-cyclic) in Go. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
go
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template