Skip to content

oh-my-gogo-protoc is a wrapper around the protobuf compiler (protoc) that automatically sets it up for use with gogo/protobuf and Go modules.

License

Notifications You must be signed in to change notification settings

oyato/oh-my-gogo-protoc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oh-my-gogo-protoc

What it is?

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.

How does it work?

  • Given your current command protoc ... --gofast_out=Mgoogle...:. my.proto, it sees you're using the gofast 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 the google/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.

Why should I use it?

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.

How do I install and use it?

  • 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.

Is it production ready?

Yes! we've literally been using it to generate over 1 go package since an hour ago, so you know it's battle tested.

About

oh-my-gogo-protoc is a wrapper around the protobuf compiler (protoc) that automatically sets it up for use with gogo/protobuf and Go modules.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages