golang 每日一庫之 goplantuml

goplantuml 是一個用 Go 編寫的工具,能夠 ** 自動將 Go 語言項目的結構生成 PlantUML 類圖(Class Diagram),適合用於 代碼可視化、架構審查、文檔編寫、團隊溝通 等場景。

項目地址

GitHub 地址:https://github.com/jfeliu007/goplantuml

概述

goplantuml 解析你的 Go 源碼,識別其中的:

最終生成符合 PlantUML 語法的 .puml 文件,供你渲染出圖像。

功能

WD9bMK

安裝

go install github.com/jfeliu007/goplantuml/cmd/goplantuml@latest

或者使用 git clone 和 go build

git clone https://github.com/jfeliu007/goplantuml
cd goplantuml/cmd/goplantuml
go build

使用方法

goplantuml ./...

輸出:將在控制檯打印出 .puml 文件內容。

將結果寫入文件:

goplantuml ./... > diagram.puml

生成圖片(需安裝 PlantUML):

plantuml diagram.puml

常用參數

IkcEDu

示例輸出

配合 VSCode + PlantUML 插件或在線工具,即可生成結構圖

示例

假設你有如下 Go 文件結構:

// models/user.go
type User struct {
    ID   int
    Name string
    Addr Address
}

type Address struct {
    City string
}

運行:

goplantuml ./models > user.puml
plantuml user.puml

將得到:

使用場景

Idz15V

標題:golang 每日一庫之 goplantuml
作者:mooncakeee
地址:http://blog.dd95828.com/articles/2025/06/20/1750429635844.html
聯繫:scotttu@163.com

本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s?__biz=MzI1MTUzMDU3NQ==&mid=2247484252&idx=1&sn=fbf3728de039a94e14fb3e65f449c244&chksm=e8a91f89d95d3845141cc59ee9f826d22fede5da69f87b80d143239786f4bf675ded9e72a220&mpshare=1&scene=1&srcid=06234ZkAwomTmkMFzQlLuUNy&sharer_shareinfo=a97b01bcc23f1ae26ea6df1d20ddc4ff&sharer_shareinfo_first=a97b01bcc23f1ae26ea6df1d20ddc4ff#rd