GoPlantUML,go代码到类图

前言

GoPlantUML 是一个开源工具,旨在简化从 Go 源代码生成 PlantUML 图的过程。使用 GoPlantUML,开发人员可以毫不费力地可视化其 Go 项目中的结构和关系,从而有助于代码理解和文档编写。通过解析 Go 源代码并生成 PlantUML 图,GoPlantUML 使开发人员能够为其代码库架构、包依赖关系和函数交互创建清晰简洁的可视化表示。该工具通过提供复杂 Go 项目的可视化概览,简化了文档编制过程并增强了团队成员之间的协作。

安装

先决条件
Golang 1.17 或更高版本

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

如果没有PlantUML插件,最好也安装一个,可以直接展示生成的内容。
也可以在线预览 https://www.plantuml.com/plantuml/uml/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000

用法

goplantuml [-recursive] 路径1 路径2 > diagram_file_name.puml
Usage of goplantuml:
  -aggregate-private-members : 显示私有成员的聚合。如果未使用-show- aggreations,则忽略。
  -hide-connections : 隐藏关系图中的所有连接
  -hide-fields : 隐藏字段
  -hide-methods : 隐藏方法
  -ignore string : 要忽略的文件夹列表,以逗号分隔
  -notes string : 要添加到图表中的注释列表,以逗号分隔
  -output string : 输出文件路径。如果省略,则默认为标准输出
  -recursive : 递归遍历所有目录
  -show-aggregations : 即使使用-hide-connections也会呈现公共聚合(默认情况下不呈现)
  -show-aliases : 即使使用-hide-connections也会呈现公共聚合(默认情况下不呈现)
  -show-compositions : 即使使用-hide-connections也显示组合
  -show-connection-labels : 在连接中显示标签以标识连接类型(例如扩展、实现、聚合、别名)
  -show-implementations : 即使使用-hide-connections也显示实现
  -show-options-as-note : 在使用该CLI运行的无明显选项的图中显示注释
  -title string : 生成图的标题
  -hide-private-members : 隐藏所有私有成员(字段和方法)

demo

package testingsupport

//MyInterface only has one method, notice the signature return value
type MyInterface interface {
	foo() bool
}

//MyStruct1 will implement the foo() bool function so it will have an "extends" association with MyInterface
type MyStruct1 struct {
}

func (s1 *MyStruct1) foo() bool {
	return true
}

//MyStruct2 will be directly composed of MyStruct1 so it will have a composition relationship with it
type MyStruct2 struct {
	MyStruct1
}

//MyStruct3 will have a foo() function but the return value is not a bool, so it will not have any relationship with MyInterface
type MyStruct3 struct {
    Foo MyStruct1
}

func (s3 *MyStruct3) foo() {

}

执行生成uml

goplantuml ./ > test.puml

模型效果
image

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程点滴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值