Preface
protoc
can 061ad4b89ea665 tools do?
protoc
.proto
C
in C++
languages such as 061ad4b89ea695, 061ad4b89ea696, Golang
, Java
, Python
, PHP
etc. through related plug-ins.
This article mainly discusses generating Golang
protoc
, such as our common commands:
protoc -I . --go_out=xxx
For more parameters, execute protoc --help
view.
Confuse
1. How do I know what plug-in is used by protoc
For example: What plug-in does --go_out
Finally learned that the protoc-gen-go
plug-in was used.
For example: What plug-in does --go-grpc_out
Finally learned that the protoc-gen-go-grpc
plug-in was used.
Also through the use of other plug-ins, a rule is summarized:
go_out
corresponds toprotoc-gen-go
plug-in;go-grpc_out
corresponds toprotoc-gen-go-grpc
plug-in;- ...
*_out
corresponds to theprotoc-gen-*
plug-in;
2. For example, what should I do if the version protoc-gen-go
plug-in used by the new and old projects is different?
I can think of two solutions:
- It is done through two environments. For example, if you hit two
docker
environments, the new project is generated in one environment, and the old project is generated in another environment. - By distinguishing plugin name to complete, for example, the new version is named
protoc-gen-go-new
, the old version is namedprotoc-gen-go-old
, used to generate a new version--go-new_out
, used to generate the old version--go-old_out
.
Obviously, the second option is less expensive.
3. What is the difference between protoc-gen-go
and protoc-gen-go-grpc
When using the parameter --go_out=plugins=grpc:xxx
generate, the generated file *.pb.go
contains the message serialization code and gRPC
code.
When using the parameter --go_out=xxx --go-grpc_out=xxx
generate, will generate two files *.pb.go
and *._grpc.pb.go
, which are the message serialization code and gRPC
code.
Why are there these two generation methods? What are the different among its? This is the information I found:
[protoc]
Original: Differences between protoc-gen-go and protoc-gen-go-grpc
4. protoc
and protoc-gen-xxx
plug-ins and grpc
and protobuf
, is there a recommended version number for the combination?
For example, the combined version number is:
protoc
v3.18.1protoc-gen-go
v1.27.1protoc-gen-go-grpc
v1.1.0grpc
v1.41.0protobuf
v1.27.1
Regarding the above version numbers, is there any version combination recommended by the official documentation? Do any friends know? Welcome to leave a comment~
Plug-in
- Parameter verification: protoc-gen-validate
- Parameter verification: go-proto-validators
- Document generation: protoc-gen-doc
- protoc-gen-grpc-gateway
- protoc-gen-openapiv2
What other useful plugins have you used? Self-recommendations and recommendations are welcome, and discuss together in the message area~
summary
The above are the solutions to my doubts and corresponding doubts, I hope it can be helpful to you.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。