godepgraph is a packages dependency graph visualization tool for your local go module project.
go install github.com/alovn/godepgraph@latest
You need run godepgraph in your go module project path, or use the parameter --path:
godepgraph --path=/workspace/bytego
bytego/internal/bytebufferpool
bytego/internal/fasttemplate
└── bytego/internal/bytebufferpool
bytego/middleware/cors
└── bytego
bytego/middleware/logger
├── bytego
└── bytego/internal/fasttemplate
bytego/middleware/pprof
└── bytego
bytego/middleware/recovery
└── bytego
bytego
If you want to display a specified package dependency, You need to know the parameter --pkg isn't the full pkg name, for examples the full pkg name is github.com/gostack-labs/bytego/middleware/cors
, the --pkg parameter use a short pkg name: bytego/middleware/cors
.
godepgraph --pkg=bytego/middleware/cors
bytego/middleware/cors
└── bytego
List dependent packages, need parameter --pkg.
godepgraph --pkg=bytego --reverse
bytego
├── bytego/middleware/cors
├── bytego/middleware/logger
├── bytego/middleware/pprof
└── bytego/middleware/recovery
The standard pkg and third pkg of dependence is not displayed by default, if want display it:
godepgraph --std --third
You can also start a local web server, and view the graph in a web browser, default listening localhost:7788.
godepgraph --web
godepgraph --web --listen=:8080
If you have the graphviz tools installed, parameter --dot can get a picture, default: godepgraph.png. you can specify an output file with --output, supoort format:jpg,png,svg,gif,dot.
godepgraph --path=/workspace/bytego --dot
godepgraph --path=/workspace/bytego --dot --output=xx.svg
the picture of godepgraph.png like this:
go mod graph tree display, for exampels:
godepgraph --mod
github.com/gostack-labs/bytego-examples
├──github.com/go-playground/validator/[email protected]
│ ├──github.com/leodido/[email protected]
│ │ └──github.com/stretchr/[email protected]
│ │ ├──github.com/stretchr/[email protected]
│ │ ├──gopkg.in/[email protected]
│ │ │ └──gopkg.in/[email protected]
│ │ ├──github.com/davecgh/[email protected]
│ │ └──github.com/pmezard/[email protected]
│ ├──github.com/rogpeppe/[email protected]
│ │ ├──github.com/pkg/[email protected]
│ │ └──gopkg.in/[email protected]
│ │ ├──github.com/kr/[email protected]
│ │ │ └──github.com/kr/[email protected]
│ │ │ └──github.com/kr/[email protected]
│ │ └──gopkg.in/[email protected]
│ ├──github.com/stretchr/[email protected]
│ │ ├──github.com/stretchr/[email protected]
│ │ ├──gopkg.in/[email protected]
│ │ │ └──gopkg.in/[email protected]
│ │ ├──github.com/davecgh/[email protected]
│ │ └──github.com/pmezard/[email protected]
...
search dependency, use --pkg:
godepgraph --mod --pkg=gopkg.in/[email protected]
gopkg.in/[email protected]
├──github.com/kr/[email protected]
│ └──github.com/kr/[email protected]
│ └──github.com/kr/[email protected]
└──gopkg.in/[email protected]
reverse dependency, use --reverse:
godepgraph --mod --pkg=gopkg.in/[email protected] --reverse
gopkg.in/[email protected]
github.com/rogpeppe/[email protected]
github.com/rogpeppe/[email protected]