Finding cycles and hidden dependencies in go mod graph
Описание и применение
Автоматический анализ графа зависимостей Go с помощью gograph позволяет быстро находить циклы и зависимые модули.
Задача
Analyzing a large Go module dependency graph to identify cycles, dependents, and hidden dependencies is difficult with raw go mod graph output.
Результат
Cycles are detected quickly (≈10 ms on a laptop) and dependents are listed for any module. The approach scales to large graphs and replaces manual grep with automated graph traversal.
Рабочий процесс
- Run
go mod graph | go run github.com/hmdsefi/gograph/examples/gomodgraph@latest cyclesto find cycles. - Run
go run github.com/hmdsefi/gograph/examples/gomodgraph@latest dependents <module>to list dependents. - Use
gomodgraph -f graph.txt cyclesordependentswith a file for larger graphs. - Optionally use gograph.dev for interactive exploration of small graphs.
Доказательства
go mod graph prints every requirement in your module graph, one per line.
I loaded it into gograph, the graph library I maintain, and wrote a small program, gomodgraph, that answers those questions.
On Prometheus it finds one cycle: go.opentelemetry.io/otel/[email protected] go.opentelemetry.io/otel/[email protected] go.opentelemetry.io/[email protected]
- Дата записи: 2026-10-12T18:41:30.582Z