golang项目代码路径生成

golang 存在非常多的interface 类型而又没有办法直观的看到代码。这里可以使用 go-callvis 工具生成代码函数调用情况。

下载安装

下载安装 go-callvis

go get -u github.com/TrueFurby/go-callvis

下载安装依赖 graphviz

brew install graphviz

使用

输入 go-callvis

go-callvis: visualize call graph of a Go program.

Usage:

  go-callvis [flags] package

  Package should be main package, otherwise -tests flag must be used.

Flags:

  -debug
    	Enable verbose log.
  -file string
    	output filename - omit to use server mode
  -focus string
    	Focus specific package using name or import path. (default "main")
  -format string
    	output file format [svg | png | jpg | ...] (default "svg")
  -group string
    	Grouping functions by packages and/or types [pkg, type] (separated by comma)
  -http string
    	HTTP service address. (default ":7878")
  -ignore string
    	Ignore package paths containing given prefixes (separated by comma)
  -include string
    	Include package paths with given prefixes (separated by comma)
  -limit string
    	Limit package paths to given prefixes (separated by comma)
  -minlen uint
    	Minimum edge length (for wider output). (default 2)
  -nodesep float
    	Minimum space between two adjacent nodes in the same rank (for taller output). (default 0.35)
  -nointer
    	Omit calls to unexported functions.
  -nostd
    	Omit calls to/from packages in standard library.
  -skipbrowser
    	Skip opening browser.
  -tags build tags
    	a list of build tags to consider satisfied during the build. For more information about build tags, see the description of build constraints in the documentation for the go/build package
  -tests
    	Include test code.
  -version
    	Show version and exit.

需要在当前项目下执行。

go-callvis flags_xxxx content main文件路径 

如:

go-callvis -minlen 3 -focus code/src -group pkg,type  code/src

最后面空格隔开指定main函数的目录。

生成后 http://localhost:7878/ 查看。