Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a protobuf go plugin plugin

https://github.com/golang/protobuf

protoc-gen-go is a plugin in protoc which generates go bindings for the input proto definition.

protoc-gen-go also has a plugin framework for which grpc is a plugin plugin https://github.com/golang/protobuf/tree/master/protoc-gen-go/grpc

$ protoc ./helloworld.proto --go_out=plugins=grpc:.

is it possible that that i write my own plugin and invoke it along with grpc plugin?

$ protoc ./helloworld.proto --go_out=plugins=grpc+myplugin:.

do i need to mandatory build my plugin into protoc-gen-go ? if no, then how will the protoc-gen-go find myplugin ?

like image 968
weima Avatar asked Feb 20 '17 05:02

weima


1 Answers

protoc-gen-go is a protoc plugin. I have written an example of another protoc plugin below for custom work. I've also used plugins which invoke other plugins.

https://github.com/drekle/protoc-gen-goexample

Protoc finds these plugins by name protoc-gen-<PLUGIN_NAME> which it expects to be a binary in your path and will interpret the args it is passed, for example --<PLUGIN_NAME>_out instead of --go_out for your plugin

like image 133
Derek Lemon Avatar answered Sep 25 '22 04:09

Derek Lemon