前言

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

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

protoc-gen-doc

protoc-gen-doc 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. --doc_out=helloworld/doc \
  2. --doc_opt=html,index.html

演示

以上篇文章 helloworld.proto 为例。

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

proto-doc.png

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

小结

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

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

推荐阅读