Go - 使用工具生成易读的 Protocol 文档

Go语言精选

共 1178字,需浏览 3分钟

 · 2022-01-23

文章目录:

  • 前言

  • 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

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

小结

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

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



推荐阅读


福利

我为大家整理了一份从入门到进阶的Go学习资料礼包,包含学习建议:入门看什么,进阶看什么。关注公众号 「polarisxu」,回复 ebook 获取;还可以回复「进群」,和数万 Gopher 交流学习。

浏览 41
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报