通过 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