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.

安装

go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc

使用

--doc_out=helloworld/doc \
--doc_opt=html,index.html

演示

以上篇文章 helloworld.proto 为例。

// 使用的 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 插件?欢迎留言评论 ~

推荐阅读

参考资料

[1]

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

c29a1bea1e8f6959181707e404caf0ee.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值