欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

GoLang調(diào)用鏈可視化go-callvis使用介紹

 更新時間:2023年02月02日 14:45:06   作者:raoxiaoya  
與鏈路追蹤(Tracing)不同,Tracing關注復雜的分布式環(huán)境中各個服務節(jié)點間的調(diào)用關系,主要用于服務治理。而我們本次探索的代碼調(diào)用鏈路則是代碼方法級別的調(diào)用關系,主要用于代碼設計

本文介紹一款工具 go-callvis,它能夠?qū)?Go 代碼的調(diào)用關系可視化出來,并提供了可交互式的 web 服務。

go get -u github.com/ofabry/go-callvis
在windows系統(tǒng)上并沒有自動安裝,需要進入下載的目錄go install
在linux系統(tǒng)上自動安裝了

> 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 默認將代碼調(diào)用關系存儲成 svg 格式的圖形。

在瀏覽器中訪問 http://localhost:7878

點擊上面的 log 模塊,將會進入 log 模塊的代碼調(diào)用交互圖中

它主要是作用是清晰的列出了包與包之間的依賴以及調(diào)用關系,用來理解項目的大致架構。

到此這篇關于GoLang調(diào)用鏈可視化go-callvis使用介紹的文章就介紹到這了,更多相關Go callvis內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 在Golang中正確的修改HTTPRequest的Host的操作方法

    在Golang中正確的修改HTTPRequest的Host的操作方法

    我們工作中經(jīng)常需要通過HTTP請求Server的服務,比如腳本批量請求接口跑數(shù)據(jù),由于一些網(wǎng)關策略,部分Server會要求請求中Header里面附帶Host參數(shù),所以本文給大家介紹了如何在Golang中正確的修改HTTPRequest的Host,需要的朋友可以參考下
    2023-12-12
  • Goland 的安裝及激活教程(window、linux下安裝)

    Goland 的安裝及激活教程(window、linux下安裝)

    這篇文章主要介紹了Golang Goland 的安裝及激活詳細教程,包括window下安裝goland和linux下安裝goland,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-10-10
  • Go在GoLand中引用github.com中的第三方包具體步驟

    Go在GoLand中引用github.com中的第三方包具體步驟

    這篇文章主要給大家介紹了關于Go在GoLand中引用github.com中第三方包的具體步驟,文中通過圖文介紹的非常詳細,對大家學習或者使用Go具有一定的參考價值,需要的朋友可以參考下
    2024-01-01
  • go通過編碼縮短字符串的長度實現(xiàn)方法步驟

    go通過編碼縮短字符串的長度實現(xiàn)方法步驟

    這篇文章主要為大家介紹了go通過編碼縮短字符串的長度實現(xiàn)方法步驟,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2024-01-01
  • Go語言新寵:pdqsort排序算法的完美打造

    Go語言新寵:pdqsort排序算法的完美打造

    pdqsort是一種新的排序算法,特別適用于Go語言,它是由Go語言團隊開發(fā)的,旨在提供高效且穩(wěn)定的排序算法,pdqsort采用了一種分治的策略,將數(shù)組分成小塊進行排序,然后再合并這些塊,需要的朋友可以參考下
    2023-10-10
  • Goland的設置與配置全過程

    Goland的設置與配置全過程

    這篇文章主要介紹了Goland的設置與配置全過程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • go中import包的大坑解決方案

    go中import包的大坑解決方案

    最近開始使用Go/GoLand 在import 自定義包時出現(xiàn)各種狀況,本文就介紹一下go中import包的大坑解決方案,具有一定的參考價值,感興趣 可以了解一下
    2022-06-06
  • golang中對

    golang中對"引用傳遞"的誤解

    這篇文章主要介紹了golang中對“引用傳遞”的誤解,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-06-06
  • 關于Gin框架中的Cookie和Session的使用方法

    關于Gin框架中的Cookie和Session的使用方法

    為了實現(xiàn)跨請求的數(shù)據(jù)共享,我們可以使用Cookie和Session,本文將結合實際案例,詳細介紹在Go語言的Gin框架中如何使用Cookie和Session,并通過代碼示例介紹的非常詳細,需要的朋友可以參考下
    2024-10-10
  • Go語言學習教程之聲明語法(譯)

    Go語言學習教程之聲明語法(譯)

    Golang 就是類C的語法,下面這篇文章主要給大家介紹了關于Go語言學習教程之聲明語法的相關資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學習學習吧。
    2017-11-11

最新評論