1

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 to protoc-gen-go plug-in;
  • go-grpc_out corresponds to protoc-gen-go-grpc plug-in;
  • ...
  • *_out corresponds to the protoc-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:

  1. 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.
  2. By distinguishing plugin name to complete, for example, the new version is named protoc-gen-go-new , the old version is named protoc-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.1
  • protoc-gen-go v1.27.1
  • protoc-gen-go-grpc v1.1.0
  • grpc v1.41.0
  • protobuf 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

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.

Recommended reading


程序员新亮
2.9k 声望1.2k 粉丝

GitHub 9K+ Star,其中适合 Go 新手的开箱即用项目 go-gin-api 5.2K Star:[链接],联系我:wx-xinliang