使用工具生成 Protocol 易读文档

前言

通过 .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.

安装

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

protoc-image

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

小结

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

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

推荐阅读

本作品采用《CC 协议》,转载必须注明作者和本文链接
日拱一卒
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!