blog

SEAN K.H. LIAO

grpc for go

proto file

syntax = "proto3";

package a.pkg;

option go_package = "github.com/example/pkg"

service Hello {
  rpc World(Msg) returns (Msg) {}
}

message Msg {}

protoc invocation

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

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

linting

protoc --lint_out=sort_imports:. *.proto

validate