grpc快速开始
protoc官方地址
# 直接安装
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
protoc需要进官网
releases 下载后丢到/usr/bin 下,目录可随机
安装protoc-gen-go-grpc
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
安装go依赖
go get google.golang.org/grpc
生成pb 和grpc.pb文件
protoc --go-grpc_out=. --go_out=. <proto file>
常见错误
protoc-gen-go: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
--go_out: protoc-gen-go: Plugin failed with status code 1.
此报错为环境未找到
protoc-gen-go ,刷新下环境变量即可
-
没生成
grpc.pb.go 文件或者pb.go 文件是因为需要在proto 文件中填写service或者message语法 -
使用格式化功能需要安装
vscode-proto3插件还需要安装clang-format 插件,并且进入releases.llvm.org/download.ht…下载LLVM 安装clang-format-
linux 安装命令:sudo apt install clang-format
-