weima
weima

Reputation: 4902

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 ?

Upvotes: 14

Views: 7926

Answers (1)

Derek Lemon
Derek Lemon

Reputation: 141

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

Upvotes: 7

Related Questions