• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

go的protoc插件调用逻辑

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

要让protoc使用插件,需要做下面事情:

Place the plugin binary somewhere in the PATH and give it the name "protoc-gen-NAME" (replacing "NAME" with the name of your plugin).

If you then invoke protoc with the parameter –NAME_out=OUT_DIR (again, replace "NAME" with your plugin's name), protoc will invoke your plugin to generate the output, which will be placed in OUT_DIR.

Place the plugin binary anywhere, with any name, and pass the –plugin parameter to protoc to direct it to your plugin like so:

protoc --plugin=protoc-gen-NAME=path/to/mybinary --NAME_out=OUT_DIR

On Windows, make sure to include the .exe suffix:

protoc --plugin=protoc-gen-NAME=path/to/mybinary.exe --NAME_out=OUT_DIR

参考: https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.compiler.plugin

产生go的 grpc 代码的插件命令为:

protoc --go_out=plugins=grpc,import_path=mypackage:. *.proto

这里通过 --NAME_out ,就能知道是需要找 protoc-gen-NAME 插件, 即 protoc-gen-go 插件。
而 --go_out=plugins=grpc 则会在 https://github.com/golang/protobuf 这里找到
https://github.com/golang/protobuf/blob/master/protoc-gen-go/grpc/grpc.go 做为插件。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap