SEANK.H.LIAO

protoc-gen-go-grpc

notes on generating grpc code for go

grpc for go

proto file

 1syntax = "proto3";
 2
 3package a.pkg;
 4
 5option go_package = "github.com/example/pkg"
 6
 7service Hello {
 8  rpc World(Msg) returns (Msg) {}
 9}
10
11message Msg {}

protoc invocation

the go generators currently take no useful options, check by looking at generator's main.go and flags set there.

1protoc \
2  --proto_path=... \                    # search path for imports, repeatable
3  --go_out=... \                        # go output directory
4  --go_opt=paths=source_relative \      # place go files next to proto defs
5  --go-grpc_out=... \                   # go-grpc output directory
6  --go-grpc_opt=paths=source_relative \ # place go-grpc files next to proto defs
7  *.proto                               # source proto files

linting

1protoc --lint_out=sort_imports:. *.proto

validate