我是靠谱客的博主 欣喜跳跳糖,这篇文章主要介绍Go - 使用工具生成易读的 Protocol 文档,现在分享给大家,希望可以做个参考。

文章目录:

  • 前言

  • protoc-gen-doc

    • 安装

    • 使用

    • 演示

  • 小结

  • 推荐阅读

前言

通过 .proto 文件能否生成更易阅读 HTML 文档?

关于这个问题,我找到了一个插件,给大家分享一下。

protoc-gen-doc

protoc-gen-doc[1] This is a documentation generator plugin for the Google Protocol Buffers compiler (protoc). The plugin can generate HTML, JSON, DocBook and Markdown documentation from comments in your .proto files.

安装

复制代码
1
go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc

使用

复制代码
1
2
--doc_out=helloworld/doc  --doc_opt=html,index.html

演示

以上篇文章 helloworld.proto 为例。

复制代码
1
2
3
4
5
6
7
8
9
10
11
// 使用的 protoc --version 为 libprotoc 3.18.1 // 使用的 protoc-gen-go --version 为 protoc-gen-go v1.27.1 // 使用的 protoc-gen-go-grpc --version 为 protoc-gen-go-grpc 1.1.0 // 使用的 protoc-gen-doc --version 为 protoc-gen-doc version 1.5.0 // 在根目录下执行 protoc 命令 protoc  --go_out=helloworld/gen  --go-grpc_out=helloworld/gen  --doc_out=helloworld/doc  --doc_opt=html,index.html  helloworld/helloworld.proto

f10d2bae71b86546a2059e24690584a8.png

同理,也可生成 JSONMarkdown 文档,去试试吧。

小结

以上,希望对你能够有所帮助。

你用过哪些好用的 protoc 插件?欢迎留言评论 ~

推荐阅读

  • Go - 如何编写 ProtoBuf 插件 (三) ?

  • Go - 如何编写 ProtoBuf 插件 (二) ?

  • Go - 如何编写 ProtoBuf 插件 (一) ?

  • Go - 关于 protoc 工具的小疑惑

  • Go - 关于 .proto 文件的小思考

参考资料

[1]

protoc-gen-doc: https://github.com/pseudomuto/protoc-gen-doc

c29a1bea1e8f6959181707e404caf0ee.png

最后

以上就是欣喜跳跳糖最近收集整理的关于Go - 使用工具生成易读的 Protocol 文档的全部内容,更多相关Go内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(71)

评论列表共有 0 条评论

立即
投稿
返回
顶部