Generating stubs using protoc
Here’s an example of what a protoc
command might look like to generate Go stubs, assuming that you’re at the root of your repository and you have your proto files in a directory called proto
:
$ protoc -I ./proto \
--go_out ./proto --go_opt paths=source_relative \
--go-grpc_out ./proto --go-grpc_opt paths=source_relative \
./proto/helloworld/hello_world.proto
We use the go
and go-grpc
plugins to generate Go types and gRPC service definitions. We’re outputting the generated files relative to the proto
folder, and we’re using the paths=source_relative
option, which means that the generated files will appear in the same directory as the source .proto
file.
This will have generated a *.pb.go
and a *_grpc.pb.go
file for proto/helloworld/hello_world.proto
.
当前内容版权归 gRPC-Gateway 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 gRPC-Gateway .