Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy GO's gRPC development environment

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the knowledge of "how to deploy the gRPC development environment of GO". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Install protoc

Protoc is a compilation tool, installed by downloading binaries and directly copying and pasting the following commands:

Mkdir-p $GOPATH/bin\ & & mkdir ~ / temp-protoc-download\ & & wget https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-linux-x86_64.zip-O / temp-protoc-download/protoc.zip\ & & cd ~ / temp-protoc-download\ & & unzip protoc.zip\ & & cp. / bin/protoc $GOPATH/bin/\ & & cd ~ /\ & & rm-rf ~ / temp-protoc-download

Execute protoc-- version to check that the protoc installation is successful:

[golang@centos7 ~] $protoc--versionlibprotoc 3.14.0 problems with installing protoc-gen-go and grpc packages

It turns out that network errors are often prompted when installing protoc-gen-go and grpc packages with go get commands, so I wrote a shell script to download the source code of protoc-gen-go and grpc packages from GitHub, compile and build locally, and achieve the same effect of go get installation.

Using the git clone command to download the source code is time-consuming (there are too many files), so the script I wrote is to download the corresponding source code package (zip file) and decompress it, which has the same effect as git clone, but takes a lot less time.

Therefore, the next action is a script to complete the installation of the protoc-gen-go and grpc packages

Install protoc-gen-go and grpc packages

Execute the following command to complete the installation of the protoc-gen-go and grpc packages:

Curl-o install-grpc.sh\ https://raw.githubusercontent.com/zq2599/blog_demos/master/files/install-grpc.sh\ & & chmod adepx. / install-grpc.sh\ & &. / install-grpc.sh

The console outputs the following information. No error indicates that the installation is successful:

... install protoc-gen-gogo: downloading google.golang.org/protobuf v1.23.0install grpcclear resourceinstall finish

You can see protoc-gen-go in the $GOPATH/bin directory:

[golang@centos7 ~] $cd $GOPATH/bin [golang@centos7 bin] $lsprotoc protoc-gen-go

At this point, the gRPC development environment is ready

A list of installation scripts

The installation of the protoc-gen-go and grpc packages is completed in install-grpc.sh. The script is shown below, which shows some simple operations: download the source code, extract it, and build it.

#! / bin/bashmkdir ~ / temp-grpc-installecho "clear old files" rm-rf $GOPATH/src/google.golang.org/grpcrm-rf $GOPATH/src/golang.org/xrm-rf $GOPATH/src/google.golang.org/protobufrm-rf $GOPATH/src/github.com/golang/protobufrm-rf $GOPATH/src/google.golang.org/genprotoecho "create directory" mkdir-p $GOPATH/src/google.golang.org/mkdir-p $GOPATH/src/golang.org/xmkdir-p $GOPATH/src/github.com / golang/echo "1. Grpc" cd ~ / temp-grpc-installwget https://github.com/grpc/grpc-go/archive/master.zip-O grpc-go.zipunzip grpc-go.zip-d $GOPATH/src/google.golang.org/cd $GOPATH/src/google.golang.org/ mv grpc-go-master grpcecho "2. X/net" cd ~ / temp-grpc-installwget https://github.com/golang/net/archive/master.zip-O net.zipunzip net.zip-d $GOPATH/src/golang.org/x/cd $GOPATH/src/golang.org/x/ mv net-master netecho "3. X/text" cd ~ / temp-grpc-installwget https://github.com/golang/text/archive/master.zip-O text.zipunzip text.zip-d $GOPATH/src/golang.org/x/cd $GOPATH/src/golang.org/x/ mv text-master textecho "4. Protobuf-go" cd ~ / temp-grpc-installwget https://github.com/protocolbuffers/protobuf -go/archive/master.zip-O protobuf-go.zipunzip protobuf-go.zip-d $GOPATH/src/google.golang.org/ cd $GOPATH/src/google.golang.org/mv protobuf-go-master protobufecho "5. Protobuf" cd ~ / temp-grpc-installwget https://github.com/golang/protobuf/archive/master.zip-O protobuf.zipunzip protobuf.zip-d $GOPATH/src/github.com/golang/cd $GOPATH/src/github.com/golang/mv protobuf-master protobufecho "6. Go -genproto "cd ~ / temp-grpc-installwget https://github.com/google/go-genproto/archive/master.zip-O go-genproto.zipunzip go-genproto.zip-d $GOPATH/src/google.golang.org/cd $GOPATH/src/google.golang.org/mv go-genproto-master genprotoecho" 7. X/sys "cd ~ / temp-grpc-installwget https://github.com/golang/sys/archive/master.zip-O sys.zipunzip sys.zip-d $GOPATH/src/golang. Org/x/cd $GOPATH/src/golang.org/xmv sys-master sysecho "install protoc-gen-go" cd $GOPATH/src/github.com/golang/protobuf/protoc-gen-go/go buildgo installecho "install grpc" cd $GOPATH/src/go install google.golang.org/grpcecho "clear resource" cd ~ / rm-rf ~ / temp-grpc-installecho "install finish"how to deploy GO's gRPC development environment" is here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report