A Go call graph analyzer inspired by clang-callgraph. Uses golang.org/x/tools (VTA, SSA, packages) to build precise call graphs for Go codebases, with an interactive REPL for exploration.
go install github.com/LiuYinCarl/gocg@latestOr build from source:
git clone https://github.com/LiuYinCarl/gocg.git
cd gocg
go install .Requires Go 1.21+.
# Analyze a Go project, enter interactive REPL
gocg /path/to/your/go/project
# Single lookup (non-interactive)
gocg /path/to/your/go/project --lookup 'pkg.FuncName'
# Exclude functions containing certain import paths
gocg . -x 'golang.org/x/tools,github.com/some/dep'
# Disable or clear cache
gocg . --no-cache
gocg . --clear-cache>>> createTransport # exact match → call graph; partial → search list
>>> ? createTransport # filter mode: only branches containing filter keywords
>>> ! createTransport # ignore mode: skip branches matching ignore keywords
>>> & createTransport # reverse references: who calls this function
>>> @ filter keyword1 keyword2 # add filter keywords
>>> @ ignore keyword1 keyword2 # add ignore keywords
>>> @ del_fi keyword # remove a filter keyword
>>> @ del_ig keyword # remove an ignore keyword
>>> @ depth 3 # set max print depth
>>> @ show # show current config
>>> @ reset # reset all config
Tab completion is supported for function names and @ subcommands.
- Load:
go/packagesloads the project and all dependencies - SSA:
go/ssabuilds static single-assignment form - VTA:
go/callgraph/vtacomputes a precise call graph (no false-positive interface calls like CHA) - Filter: Only functions defined under the project directory are expanded; external calls appear as leaf nodes
- Cache: Results are cached in
.gocg-cache/under the project directory, keyed by SHA256 of all.gofile mtimes/sizes
| Flag | Description |
|---|---|
<directory> |
Go project directory to analyze (default: .) |
-x p1,p2,... |
Exclude functions whose full import path contains any of these substrings |
--lookup func |
Print call graph for a function and exit (no REPL) |
--no-cache |
Skip reading/writing cache |
--clear-cache |
Remove all cached files and exit |
| Feature | clang-callgraph | gocg |
|---|---|---|
| Language | C/C++ (libclang) | Go (x/tools) |
| Input | compile_commands.json / .cpp |
Go project directory |
| Call graph algorithm | Clang AST walk | VTA (Variable Type Analysis) |
| Interactive REPL | ✅ | ✅ |
| Filter / Ignore / Ref | ✅ | ✅ |
| Tab completion | ✅ | ✅ |
| Cache | ✅ | ✅ |