oh-my-gogo-protoc is a wrapper around the protobuf compiler (protoc
) that automatically sets it up for use with https://github.com/gogo/protobuf and Go modules.
- Given your current command
protoc ... --gofast_out=Mgoogle...:. my.proto
, it sees you're using thegofast
generator and: - Automatically runs
go install github.com/gogo/protobuf/protoc-gen-gofast
. - Then it runs
protoc --proto_path=...git.luolix.top/gogo/protobuf/protobuf@1... my.proto
i.e. with the correct include paths** and thegoogle/protobuf/*.proto=github.com/gogo/protobuf/types
mappings.
Replace gofast_out
with gogoslick_out
or any other generator you prefer. It will figure it out and install and set up the appropriate binary.
It makes working with Go modules and gogo/protobuf easy and pain-free.
Typically, to use gogo/protobuf you run protoc with a bunch of params like -I$GOPATH/src/...
. This doesn't work for Go modules because the directory is at $GOPATH/pkg/mod/github.com/gogo/protobuf@version/...
so you need a work-around involving go list -f {{.Dir}}...
which may or may not work. It also doesn't work if $GOPATH
is a list of directories.
- In your module dir, run
go get oya.to/oh-my-gogo-protoc
. - In your source file add or edit your go generate directive
//go:generate go run oya.to/oh-my-gogo-protoc --gofast_out=. my.proto
. That's it. - Don't forget to install the gogo/proto deps you need e.g.
go get github.com/gogo/protobuf/protoc-gen-gofast
Can I use it with Twirp RPC?
Yes, if you pass --twirp_out
, it knows to automatically go install github.com/twitchtv/twirp/protoc-gen-twirp
as well.
Yes! we've literally been using it to generate over 1 go package since an hour ago, so you know it's battle tested.