protoc
, usually from package managerprotoc-gen-go
: go get google.golang.org/protobuf/cmd/protoc-gen-go
for message outputprotoc-gen-go-grpc
: go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
for service output 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 {}
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
protoc-gen-lint
: go get github.com/ckaznocha/protoc-gen-lint
1protoc --lint_out=sort_imports:. *.proto