通過 protoc-gen-grpc-web 插件自動生成 gPRC 服務接口的 JavaScript 調用代碼


1. 安裝 protoc and protoc-gen-grpc-web 插件

  protoc 下載: https://github.com/protocolbuffers/protobuf/releases

  protoc-gen-grpc-web 插件下載: https://github.com/grpc/grpc-web/releases

 

2. 將 protoc and protoc-gen-grpc-web 安裝目錄的 Bin 添加到系統環境變量

 

3. 打開 CMD 切換目錄到 gRPC 的 xxx.proto 下

  運行如下命令,生成對應的 xxx_grpc_web_pb.js 和 xxx_pb.js 文件:

protoc -I=. xxx.proto --js_out=import_style=commonjs:. --grpc-web_out=import_style=commonjs,mode=grpcwebtext:.

 

 

參考:https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld#generate-protobuf-messages-and-client-service-stub

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM