Golang 官方說明使用 go get google.golang.org/grpc 進行安裝,但是由於代碼已經轉移到github上,然而源碼中的包依賴還是google.golang.org形式。所以我們需要自己去github上clone相關的包。
相信大家已經配置好GOPATH換將變量。
以下是安裝方式(推薦使用Git Bash客戶端):
git clone https://github.com/golang/net.git $GOPATH/src/golang.org/x/net git clone https://github.com/golang/text.git $GOPATH/src/golang.org/x/text
git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpc
git clone https://github.com/google/go-genproto.git $GOPATH/src/google.golang.org/genproto
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
然后進入到$GOPATH/src目錄下。
go install google.golang.org/grpc
這就ok了。
PS:
go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
這句主要是安裝protobuf,會下載 protoc-gen-go.exe和protoc.exe文件到$GOPATH/bin目錄下。如果protoc.exe下載不成功(可以自行到$GOPATH/bin下查看),可以點擊鏈接https://github.com/google/protobuf/releases,去下載protoc-3.8.0-win64.zip,解壓后可以看到bin目錄下有protoc.exe文件,直接拷貝到$GOPATH/bin下。