Skip to content

Instantly share code, notes, and snippets.

@tooolbox
Last active September 28, 2019 18:26
Show Gist options
  • Save tooolbox/b6ee8e470691ac469ac27c19ab3fa6fa to your computer and use it in GitHub Desktop.
Save tooolbox/b6ee8e470691ac469ac27c19ab3fa6fa to your computer and use it in GitHub Desktop.
The protobuf documentation you wish you had when you started

Generally: protoc -flag param:param:param target-file.proto --plugin_flag=key=value,key=value:./dest/

For example: protoc -I .:.. foo.proto --go_out=plugins=grpc,paths=source_relative:.

This means:

  1. Run protoc on foo.proto
  2. Any other proto files in the current directory or the parent directory should be available for import.
  3. Generate a foo.pb.go file for gRPC using protoc-gen-go.
  4. If foo.proto were to have a declaration of option go_package = "github.com/bar/baz"; the protoc-gen-go plugin would normally create ./github.com/bar/baz/foo.pb.go but paths=source_relative makes it simply write ./foo.pb.go.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment