栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

如何使用plantUML生成go项目的UML图?(mac)

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用plantUML生成go项目的UML图?(mac)

0 前言

当时看想一下项目的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插件即可。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/944168.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号