当时看想一下项目的UML图,在网上找了好几篇文章,试了很久都么有成功,我也不知道是不是他们教程有问题,后面自己琢磨,在github上找了几个项目,试了一下,终于ok了。
1 安装goplantuml项目这个项目主要用于生成项目的*.puml文件的,这一步很重要。
go get github.com/jfeliu007/goplantuml/parser go get github.com/jfeliu007/goplantuml/cmd/goplantuml cd $GOPATH/src/github.com/jfeliu007/goplantuml go install ./...
使用上述命令安装,安装之后就可以使用了。
用法# 选择多个文件生成,也可以直接一个目录 goplantuml [-recursive] path/to/gofiles path/to/gofiles2 goplantuml [-recursive] path/to/gofiles path/to/gofiles2 > diagram_file_name.puml
选项:
Usage of goplantuml:
-aggregate-private-members
Show aggregations for private members. Ignored if -show-aggregations is not used.
-hide-connections
hides all connections in the diagram
-hide-fields
hides fields
-hide-methods
hides methods
-ignore string
comma separated list of folders to ignore
-notes string
Comma separated list of notes to be added to the diagram
-output string
output file path. If omitted, then this will default to standard output
-recursive
walk all directories recursively
-show-aggregations
renders public aggregations even when -hide-connections is used (do not render by default)
-show-aliases
Shows aliases even when -hide-connections is used
-show-compositions
Shows compositions even when -hide-connections is used
-show-connection-labels
Shows labels in the connections to identify the connections types (e.g. extends, implements, aggregates, alias of
-show-implementations
Shows implementations even when -hide-connections is used
-show-options-as-note
Show a note in the diagram with the none evident options ran with this CLI
-title string
Title of the generated diagram
-hide-private-members
Hides all private members (fields and methods)
选项很多,用的多的就两个:-output和-recursive,设置*.puml文件输出路径和是否递归生成。
例如:goplantuml $GOPATH/src/github.com/jfeliu007/goplantuml/parser
生成了*.puml文件之后,我们需要选择工具进行生成图片。
注意:使用前确认是否安装Graphviz 。
2 生成UML图片有两种方法。
使用plantuml.jar文件生成- 下载plantuml.jar文件,百度可以找到官网
- 如果没有安装java环境自行安装
生成图片命令:java -jar plantuml.jar *.puml
这样就可以生成UML图片了。
注意: 如果图片太大,需要修改图片大小和分辨率。
参考:https://blog.csdn.net/SweetTool/article/details/108208953
可以选择vscode或者goland作为生成工具,安装plantuml插件即可。



