1. 安裝 protobuf
把解壓后的 bin 目錄下的 protoc.exe 放入到 GOBIN (go env 查看) 中
2. 安裝 grpc
Git clone https://github.com/grpc/grpc-go
將grpc-go文件夾重命名為grpc,放入到google.golang.org中,完整路徑如下
C:\GOPATH\src\google.golang.org\grpc
3. 安裝 genproto
Git clone https://github.com/google/go-genproto
將go-genproto文件夾重命名為genproto,放到google.golang.org下,完整路徑如下
C:\GOPATH\src\google.golang.org\genproto
4. 安裝 proto
go get -u github.com/golang/protobuf/proto
5. 安裝 protoc-gen-go
go get -u github.com/golang/protobuf/protoc-gen-go
6. 下載依賴包
創(chuàng)建目錄 C:\GOPATH\src\golang.org\x
進入 x 目錄
git clone https://github.com/golang/net.git
git clone https://github.com/golang/text.git
7. 使用
cd 到 src\google.golang.org\grpc\examples\helloworld目錄
執(zhí)行命令生成代碼 helloworld.pb.go
protoc -I ./helloworld --go_out=plugins=grpc:./helloworld ./helloworld\helloworld.proto
- 進入 \src\google.golang.org\grpc\examples\helloworld\greeter_server 目錄
執(zhí)行go run main.go - 進入 \src\google.golang.org\grpc\examples\helloworld\greeter_client 目錄
執(zhí)行go run main.go yourname