Welcome to my GitHub

Here classification and summary of xinchen all original (including supporting source code) : github.com/zq2599/blog…

GRPC learning series of articles links

  1. Deploy and set GO on CentOS7
  2. Prepare gRPC development environment for GO
  3. The first GO version of gRPC development
  4. Actual combat four kinds of service methods
  5. GRPC – Gateway of actual combat
  6. GRPC – Gateway integration swagger

This paper gives an overview of

  • In this article, the second part of the gRPC learning series, the previous article installed GO in the CentOS7 environment, the next step is to prepare the gRPC development environment, in general, there are three steps:

Install the protoc

  1. Protoc is a compilation tool, installed by downloading binary files, directly copy and paste the following command to execute:
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-downloadCopy the code
  1. Run protoc –version to check whether the protoc installation is successful:
[golang@centos7 ~]$protoc --version libprotoc 3.14.0Copy the code

Problems encountered installing protoc-gen-go and GRPC packages

  • Protoc-gen-go and GRPC packages installed with go get command often cause network error, so I wrote a shell script, protoc-gen-go and GRPC package source downloaded from GitHub, local compilation and construction, to achieve the same effect of go get installation;
  • Using git clone command to download source code is time-consuming (the number of files is too large), so I wrote the script to download the corresponding source package (zip file), and then decompress, which has the same effect as git Clone but much less time.
  • Therefore, the next operation is a script to install the Protoc-Gen-go and GRPC packages;

Install protoc-Gen-go and GRPC packages

  1. To install the protoc-gen-go and GRPC packages, run the following command:
curl -o install-grpc.sh \
https://raw.githubusercontent.com/zq2599/blog_demos/master/files/install-grpc.sh \
&& chmod a+x ./install-grpc.sh \
&& ./install-grpc.sh
Copy the code
  1. The installation is successful if the following information is displayed on the console:
. Install protoc - gen - go go: downloading google.golang.org/protobuf v1.23.0 install GRPC clear resource install finishCopy the code
  1. Protoc-gen-go can be seen in the $GOPATH/bin directory:
[golang@centos7 ~]$ cd $GOPATH/bin
[golang@centos7 bin]$ ls
protoc  protoc-gen-go
Copy the code
    • At this point, the gRPC development environment has been ready, the next can start combat;

Installation Script Overview

Both the protoc-gen-go and GRPC packages are installed in install-grpc.sh. The script content is as follows, which shows the simple operations: download source code, decompress, build

#! /bin/bashmkdir ~/temp-grpc-install echo "clear old files" rm -rf $GOPATH/src/google.golang.org/grpc rm -rf $GOPATH/src/golang.org/x rm -rf $GOPATH/src/google.golang.org/protobuf rm -rf $GOPATH/src/github.com/golang/protobuf rm -rf $GOPATH/src/google.golang.org/genproto echo "create directory" mkdir -p $GOPATH/src/google.golang.org/ mkdir -p $GOPATH/src/golang.org/x mkdir -p $GOPATH/src/github.com/golang/ echo "1. grpc" cd ~/temp-grpc-install wget https://github.com/grpc/grpc-go/archive/master.zip -O grpc-go.zip unzip grpc-go.zip -d $GOPATH/src/google.golang.org/ cd  $GOPATH/src/google.golang.org/ mv grpc-go-master grpc echo "2. x/net" cd ~/temp-grpc-install wget https://github.com/golang/net/archive/master.zip -O net.zip unzip net.zip -d $GOPATH/src/golang.org/x/ cd $GOPATH/src/golang.org/x/ mv net-master net echo "3. x/text" cd ~/temp-grpc-install wget https://github.com/golang/text/archive/master.zip -O text.zip unzip text.zip -d $GOPATH/src/golang.org/x/ cd $GOPATH/src/golang.org/x/ mv text-master text echo "4. protobuf-go" cd ~/temp-grpc-install wget https://github.com/protocolbuffers/protobuf-go/archive/master.zip -O protobuf-go.zip unzip protobuf-go.zip -d $GOPATH/src/google.golang.org/ cd $GOPATH/src/google.golang.org/ mv protobuf-go-master protobuf echo "5. protobuf" cd ~/temp-grpc-install wget https://github.com/golang/protobuf/archive/master.zip -O protobuf.zip unzip protobuf.zip -d $GOPATH/src/github.com/golang/ cd $GOPATH/src/github.com/golang/ mv protobuf-master protobuf echo "6. go-genproto" cd ~/temp-grpc-install wget https://github.com/google/go-genproto/archive/master.zip -O go-genproto.zip unzip go-genproto.zip -d $GOPATH/src/google.golang.org/ cd $GOPATH/src/google.golang.org/ mv go-genproto-master genproto echo "7. x/sys" cd ~/temp-grpc-install wget https://github.com/golang/sys/archive/master.zip -O sys.zip unzip sys.zip -d $GOPATH/src/golang.org/x/ cd $GOPATH/src/golang.org/x mv sys-master sys echo "install protoc-gen-go" cd $GOPATH/src/github.com/golang/protobuf/protoc-gen-go/ go build go install echo "install grpc" cd $GOPATH/src/ go install  google.golang.org/grpc echo "clear resource" cd ~/ rm -rf ~/temp-grpc-install echo "install finish"Copy the code

You are not alone, Xinchen original accompany all the way

  1. Java series
  2. Spring series
  3. The Docker series
  4. Kubernetes series
  5. Database + middleware series
  6. The conversation series

Welcome to pay attention to the public number: programmer Xin Chen

Wechat search “programmer Xin Chen”, I am Xin Chen, looking forward to enjoying the Java world with you…

Github.com/zq2599/blog…