Home >Backend Development >Golang >Detailed explanation of how to build grpc environment in go language

Detailed explanation of how to build grpc environment in go language

藏色散人
藏色散人forward
2020-08-17 13:27:463124browse

The following column Golang Language Tutorial will introduce to you how to build the go language grpc environment. I hope it will be helpful to friends in need!

Detailed explanation of how to build grpc environment in go language

Installing grpc:
The command given by the official website is:

go get -u google.golang.org/grpc

It seems that it can’t be used, it can’t connect to the server, even if I hang up xxx It's useless. I have no choice but to install it in a roundabout way. Anyway, the code is available on github, so I clone it from github.

# 下载grpc-go
git clone https://github.com/grpc/grpc-go.git %GOPATH%/src/google.golang.org/grpc

# 下载golang/net
git clone https://github.com/golang/net.git %GOPATH%/src/golang.org/x/net

# 下载golang/text
git clone https://github.com/golang/text.git %GOPATH%/src/golang.org/x/text

# 下载go-genproto
git clone https://github.com/google/go-genproto.git %GOPATH%/src/google.golang.org/genproto

# 安装
cd $GOPATH/src/go install google.golang.org/grpc

At this time, a lot of errors will be reported because there are still a few missing packages. What is protobuf

git clone https://e.coding.net/robinqiwei/googleprotobuf.git %GOPATH%/src/google.golang.org/protobuf

clone is to complete protobuf and then you execute

go install google.golang.org/grpc

to succeed!

Something special to note
There must be a go.mod file
In addition, grpc cannot be automatically loaded when I write the client. I don’t know what the hell is going on?
"google.golang.org/grpc" is written into the import, and then the command line is executed

go mod tidy

and it is automatically downloaded. Didn't I clone it before? No matter, it can be used normally anyway!

For more golang technical articles, please visit the golang tutorial column!

The above is the detailed content of Detailed explanation of how to build grpc environment in go language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete