Golang 可视化工具之go 您所在的位置:网站首页 代码可视化分析工具怎么用的 Golang 可视化工具之go

Golang 可视化工具之go

2023-08-26 19:05| 来源: 网络整理| 查看: 265

小知识,大挑战!本文正在参与「程序员必备小知识」创作活动。

本文已参与 「掘力星计划」 ,赢取创作大礼包,挑战创作激励金。

一 背景

日常我们会看一些开源项目,或者想看自己写的代码可视化,在golang中可以利用工具实现,go-callvis是以图片的形式展示了go程序的调用关系,在看复杂项目时尤其有用。

二 go-callvies 简介 2.1 工具简介

Go-callvis 是一个开发工具,用于帮助使用交互式视图可视化 Go 程序的调用图。

此工具的目的是为开发人员提供一个可视化的 Go 程序概览,使用来自调用图的数据及其与包和类型的关系。这在大型项目中特别有用,因为这些项目的代码复杂度要高得多,或者只是简单地试图理解其他人的代码。

2.2 特性 支持go mod 程序中的特定焦点包 点击软件包,使用交互式查看器快速切换焦点 按类型按包和/或方法分组函数 过滤器包到特定的导入路径前缀 忽略标准库中的函数 省略各种类型的函数调用 三 安装 go get安装 $ go get -u github.com/ofabry/go-callvis 源码编译安装 $ git clone https://github.com/ofabry/go-callvis.git cd go-callvis && make install 四 输出示例

它运行指针分析来构造程序的调用图,并使用数据生成点格式的输出,可以使用 Graphviz 工具进行渲染。

五 安装 go get -u github.com/ofabry/go-callvis # or git clone https://github.com/ofabry/go-callvis.git cd go-callvis && make install 六 使用

go-callvis [可选参数]

1)使用浏览器交互展示

默认情况下,HTTP服务器在http://localhost:7878/上侦听,请使用选项`-http="ADDR:PORT"`更改HTTP服务器地址。

2)静态输出

要生成单个输出文件,使用选项-file=选择输出文件目标。

输出格式默认为svg,使用选项-format=选择其他输出格式。

3)其他参数

-debug 输出详细日志 -file string 以文件新式输出结果,并将忽略server交互模式 -focus string Focus specific package using name or import path. (default "main") -format string 输出文件的格式 [svg | png | jpg | ...] (默认 "svg") -graphviz 使用Graphviz渲染图像 -group string 分组功能,根据包 与/或 类型分组 [pkg, type] (用逗号分开) (默认 "pkg"),例如 -group pkg,type -http string HTTP 服务地址 (默认 ":7878") -ignore string 忽略包含给定前缀的包路径(用逗号分开) -include string 包含具有给定前缀的包路径 (用逗号分开) -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 忽略对未导出函数的调用。 -nostd 忽略标准库的调用 -skipbrowser 跳过打开浏览器 -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 包含测试代码 -version 显示版本号 1)解析main包 go-callvis -skipbrowser -nostd ./ 2)解析testPkg包 go-callvis -group pkg,type -focus testPkg github.com/项目具体路径 简单示例 $ go-callvis -format png -group pkg,type -focus github.com/kaliarch/cobra /cmd/app github.com/kaliarch/cobra 2021/08/18 11:22:12 http serving at http://localhost:7878 2021/08/18 11:22:21 converting dot to png.. 2021/08/18 11:22:22 serving file: /var/folders/wn/367g1v9n1bv0sg1k8qldzym80000gn/T/go-callvis_export.png

参考链接 github.com/TrueFurby/g… 其他

「欢迎在评论区讨论,掘金官方将在掘力星计划活动结束后,在评论区抽送100份掘金周边,抽奖详情见活动文章」。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有