安裝grpc 因爲國內的網絡環境沒法經過執行go get google.golang.org/grpc命令直接安裝,只能經過以下方式進行安裝: 建立google.golang.org相關目錄 在GOPATHsrc目錄下建立google.golang.org目錄及其子目錄src 下載gRPC 將命令行的當前路徑切換至GOPATH\src\google.golang.org\src,執行以下命令 git clone https://github.com/grpc/grpc-go 下載完成後將grpc-go的文件夾名稱修改成grpc 下載genproto 將命令行的當前路徑切換至GOPATH\src\google.golang.org\src,執行以下命令 git clone https://github.com/google/go-genproto 下載完成後將go-genproto的文件夾名稱修改成genproto 下載text包 將命令行的當前路徑切換至GOPATH\src\golang.org,執行以下命令 git clone https://github.com/golang/text.git 下載net包 將命令行的當前路徑切換至GOPATH\src\golang.org,執行以下命令 git clone https://github.com/golang/net.git 安裝proto 執行以下命令 go get -u github.com/golang/protobuf/proto 安裝protoc-gen-go 執行以下命令 go get -u github.com/golang/protobuf/protoc-gen-go 安裝gRPC 將命令行的當前路徑切換至GOPATHsrc,執行以下命令 go install google.golang.org/grpc
gRPC安裝驗證 生成執行代碼 將命令行的當前路徑切換至GOPATH\google.golang.org\grpc\examples\helloworld\helloworld,執行以下命令 protoc --go_out=plugins=grpc:. helloworld.proto 命令執行完成後,在GOPATH\google.golang.org\grpc\examples\helloworld\helloworld目錄下會生成helloworld.pb.go文件 啓動gRPC Server 將命令行的當前路徑切換至GOPATH\google.golang.org\grpc\examples\helloworld\greeter_server,執行以下命令啓動gRPC Server go run main.go 啓動gRPC客戶端 將命令行的當前路徑切換至GOPATH\google.golang.org\grpc\examples\helloworld\greeter_client,執行以下命令啓動gRPC客戶端 go run main.go執行該命令後,命令行中出現2019/06/18 13:54:21 Greeting: Hello world信息代表gRPC安裝成功並經過驗證。