protokit
A starter kit for building protoc-plugins. Rather than write your own, you can just use an existing one.
See the examples directory for uh...examples.
Getting Started
package main
import (
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/protoc-gen-go/plugin"
"github.com/pseudomuto/protokit"
_ "google.golang.org/genproto/googleapis/api/annotations"
"log"
)
func main() {
if err := protokit.RunPlugin(new(plugin)); err != nil {
log.Fatal(err)
}
}
type plugin struct{}
func (p *plugin) Generate(in *plugin_go.CodeGeneratorRequest) (*plugin_go.CodeGeneratorResponse, error) {
descriptors := protokit.ParseCodeGenRequest(req)
resp := new(plugin_go.CodeGeneratorResponse)
for _, d := range descriptors {
fileName :=
content :=
resp.File = append(resp.File, &plugin_go.CodeGeneratorResponse_File{
Name: proto.String(fileName),
Content: proto.String(content),
})
}
return resp, nil
}
Then invoke your plugin via protoc
. For example (assuming your app is called thingy
):
protoc --plugin=protoc-gen-thingy=./thingy -I. --thingy_out=. rpc/*.proto