go 的 protoc 插件调用逻辑
ghj1976 · · 3972 次点击 · · 开始浏览要让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 做为插件。
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
要让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 做为插件。