A tool to build dependency graph for go programs based on dependency injection functions.
go install github.com/emilien-puget/go-dependency-graph/cmd/go-dependency-graph@latest
You can customize the behavior of the tool using these parameters:
--generate-diag=false
: Disable diagram generation.
--generate-mocks=false
: Disable mocks generation.
--project=<path to project>
: the targeted project, default is current directory.
go-dependency-graph --project=<path to project> --diag-result=<result file> --diag-generator=<generator>
Available generators include:
c4_plantuml_component
, default, a components diagrams using c4 plantumlmermaid_class
, a class diagram using mermaid
Please note that GitHub does not support the namespace feature of MermaidJS class diagrams. You can use the mermaid cli to generate SVG, PNG, or PDF files.
go-dependency-graph --project=<path to project> --mock-result=<result directory> --mock-generator=<generator>
mock-result default value is the mocks
directory at the root of the project dir.
Available generators include:
mockery
, default, mockery
@startuml
!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Component.puml
title testdata/named_inter
Container_Boundary(testdata/named_inter, "testdata/named_inter") {
Component("A", "A", "", "")
Component("B", "B", "", "")
Component("C", "C", "", "")
Component("D", "D", "", "")
}
Container_Boundary(pa, "pa") {
Component("pa_A", "A", "", "A pa struct.")
}
Rel("A", "B", "FuncA")
Rel("A", "B", "FuncB")
Rel("A", "D", "FuncA")
Rel("B", "C", "FuncA")
Rel("D", "pa_A", "FuncFoo")
@enduml
classDiagram
namespace testdata_named_inter {
class `testdata/named_inter/A`
class `testdata/named_inter/B` {
FuncA()
FuncB()
}
class `testdata/named_inter/C` {
FuncA()
}
class `testdata/named_inter/D` {
FuncA()
}
}
namespace testdata_named_inter_pa {
class `testdata/named_inter/pa/A` {
FuncFoo(foo string)(bar int, err error)
}
}
`testdata/named_inter/A` ..> `testdata/named_inter/B`: FuncA
`testdata/named_inter/A` ..> `testdata/named_inter/B`: FuncB
`testdata/named_inter/A` ..> `testdata/named_inter/D`: FuncA
`testdata/named_inter/B` ..> `testdata/named_inter/C`: FuncA
`testdata/named_inter/D` ..> `testdata/named_inter/pa/A`: FuncFoo