網站首頁 編程語言 正文
本文介紹一款工具 go-callvis,它能夠將 Go 代碼的調用關系可視化出來,并提供了可交互式的 web 服務。
go get -u github.com/ofabry/go-callvis
在windows系統上并沒有自動安裝,需要進入下載的目錄go install
在linux系統上自動安裝了
> 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")
? -graphviz
? ? ? ? Use Graphviz's dot program to render images.
? -group string
? ? ? ? Grouping functions by packages and/or types [pkg, type] (separated by comma) (default "pkg")
? -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 buil
d constraints in the documentation for the go/build package
? -tests
? ? ? ? Include test code.
? -version
? ? ? ? Show version and exit.
依賴
- Go 1.17+
- Graphviz (可選,當工具指定了
-graphviz
時需要)
測試代碼
package main import ( "log" "net" ) func main() { // Part 1: create a listener l, err := net.Listen("tcp", ":8000") if err != nil { log.Fatalf("Error listener returned: %s", err) } defer l.Close() for { // Part 2: accept new connection c, err := l.Accept() if err != nil { log.Fatalf("Error to accept new connection: %s", err) } // Part 3: create a goroutine that reads and write back data go func() { log.Printf("TCP session open") defer c.Close() for { d := make([]byte, 1024) // Read from TCP buffer _, err := c.Read(d) if err != nil { log.Printf("Error reading TCP session: %s", err) break } log.Printf("reading data from client: %s\n", string(d)) // write back data to TCP client _, err = c.Write(d) if err != nil { log.Printf("Error writing TCP session: %s", err) break } } }() } }
在linux上可以正常運行,windows上會報錯
> go-callvis main67.go
2022/09/21 15:28:50 http serving at http://localhost:7878
go-callvis 默認將代碼調用關系存儲成 svg 格式的圖形。
在瀏覽器中訪問 http://localhost:7878
點擊上面的 log 模塊,將會進入 log 模塊的代碼調用交互圖中
它主要是作用是清晰的列出了包與包之間的依賴以及調用關系,用來理解項目的大致架構。
原文鏈接:https://blog.csdn.net/raoxiaoya/article/details/126974420
相關推薦
- 2022-07-16 TritonObjDet新增要素的方法
- 2022-03-27 Android使用kotlin實現多行文本上下滾動播放_Android
- 2023-01-14 C/C++高精度(加減乘除)算法的實現_C 語言
- 2022-07-26 Python基礎之模塊詳解_python
- 2023-04-01 路由react-router-dom的基本使用教程_React
- 2022-08-13 VMware vCenter 無法創建自定義規范
- 2022-05-17 NoSQL中的“BASE”特性
- 2022-05-11 深入理解AQS之獨占鎖ReentrantLock源碼分析
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支