Skip to content

Commit

Permalink
feat: update grpc tools and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
daheige committed May 14, 2022
1 parent 1e983e6 commit b41be51
Show file tree
Hide file tree
Showing 13 changed files with 411 additions and 92 deletions.
44 changes: 27 additions & 17 deletions docs/centos7-protoc-install.md → docs/centos7-grpc-install.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# go v1.16.15安装

cd /usr/local
sudo wget https://golang.google.cn/dl/go1.18.2.linux-amd64.tar.gz
sudo tar zxvf go1.18.2.linux-amd64.tar.gz
sudo chown -R $USER /usr/local/go

设置好go env
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,direct
go env -w CGO_ENABLED=0

# centos7 protoc工具安装

1、下载https://github.com/protocolbuffers/protobuf/archive/v3.11.4.tar.gz
1、下载https://github.com/protocolbuffers/protobuf/archive/v3.15.8.tar.gz
cd /usr/local/src
sudo wget https://github.com/protocolbuffers/protobuf/archive/v3.11.4.tar.gz
sudo wget https://github.com/protocolbuffers/protobuf/archive/v3.15.8.tar.gz

2、开始安装
sudo mv v3.11.4.tar.gz protobuf-3.11.4.tar.gz
sudo tar zxvf protobuf-3.11.4.tar.gz
cd protobuf-3.11.4
sudo mv v3.15.8.tar.gz protobuf-3.15.8.tar.gz
sudo tar zxvf protobuf-3.15.8.tar.gz
cd protobuf-3.15.8
sudo yum install gcc-c++ cmake libtool
$ sudo mkdir /usr/local/protobuf

Expand All @@ -24,25 +36,23 @@
安装完成后,查看版本:
$ cd /usr/local/protobuf/bin
$ ./protoc --version
libprotoc 3.11.4
libprotoc 3.15.8
建立软链接
$ sudo ln -s /usr/local/protobuf/bin/protoc /usr/bin/protoc

# go protoc工具安装

执行如下命令
go get -u github.com/golang/protobuf/proto

go get -u github.com/golang/protobuf/protoc-gen-go

go get -u google.golang.org/grpc

cd $GOPATH/pkg/mod/github.com/golang/[email protected]/protoc-gen-go
go install

cd $GOPATH/pkg/mod/github.com/golang/[email protected]/proto
go install
go install github.com/golang/protobuf/protoc-gen-go@latest
go install google.golang.org/grpc@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@latest
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@latest
go get -u github.com/go-playground/validator/v10
go install github.com/golang/mock/mockgen@latest
go install github.com/favadi/protoc-go-inject-tag@latest

# centos7 php grpc_php工具安装

Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions docs/grpc-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ RUN wget -q -P /tmp/temp/ https://github.com/protocolbuffers/protobuf/releases/d

RUN go env -w GO111MODULE=on; go env -w GOPROXY=https://goproxy.cn,https://mirrors.aliyun.com/goproxy/,direct;go env -w CGO_ENABLED=0 && \
go get -u github.com/golang/protobuf/proto && \
go get -u github.com/golang/protobuf/protoc-gen-go && \
go get -u google.golang.org/grpc && \
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc && \
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway && \
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger && \
go install github.com/golang/protobuf/protoc-gen-go@latest && \
go install google.golang.org/grpc@latest && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest && \
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@latest && \
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@latest && \
go get -u github.com/go-playground/validator/v10 && \
go get -u github.com/golang/mock/mockgen && \
go get -u github.com/favadi/protoc-go-inject-tag
go install github.com/golang/mock/mockgen && \
go install github.com/favadi/protoc-go-inject-tag@latest
File renamed without changes.
53 changes: 53 additions & 0 deletions docs/nodejs-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# install nodejs

cd /usr/local/
sudo wget https://nodejs.org/dist/v12.16.2/node-v12.16.2-linux-x64.tar.xz
sudo apt-get install xz-utils
sudo xz -d node-v12.16.2-linux-x64.tar.xz
sudo tar xvf node-v12.16.2-linux-x64.tar
sudo mv node-v12.16.2-linux-x64 nodejs

# For the convenience of the current user, set nodejs to belong to the current user,
# which is not recommended in the production environment

sudo chown -R $USER /usr/local/nodejs
sudo ln -s /usr/local/nodejs/bin/npm /usr/bin/npm
sudo chmod +x /usr/bin/npm

# add env path
vim ~/.bashrc
export NODEJS_HOME=/usr/local/nodejs
export PATH=$NODEJS_HOME/bin:$PATH

:wq
source ~/.bashrc

# install cnpm

npm install -g cnpm --registry=https://registry.npm.taobao.org

# nodejs gprc install

cnpm install grpc-tools -g
cnpm install google-protobuf -g
cnpm install grpc -g

# nodejs generate code

sh bin/nodejs-generate.sh

# nodejs client run

cd gmicro/example/clients/nodejs
cnpm install
node hello.js
{
wrappers_: null,
messageId_: undefined,
arrayIndexOffset_: -1,
array: [ 'hello,heige', 'call ok' ],
pivot_: 1.7976931348623157e+308,
convertedPrimitiveFields_: {}
}
call ok
hello,heige
28 changes: 23 additions & 5 deletions example/bin/nodejs-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ if [ -z $protoExec ]; then
exit 0
fi

grpc_node_plugin=$(which "grpc_node_plugin")
if [ -z $grpc_node_plugin ]; then
echo 'Please install grpc_node_plugin'
exit 0
jsProtoExec=$(which "grpc_tools_node_protoc")
if [ -z $jsProtoExec ]; then
grpc_node_plugin=$(which "grpc_node_plugin")
if [ -z $grpc_node_plugin ]; then
echo 'Please install grpc_node_plugin or grpc_tools_node_protoc';
exit 0
fi
fi

echo "\n\033[0;32mGenerating codes...\033[39;49;0m\n"
Expand All @@ -21,13 +24,28 @@ mkdir -p $nodejs_pb_dir

cd $root_dir/protos

$protoExec --js_out=import_style=commonjs,binary:$nodejs_pb_dir --plugin=protoc-gen-grpc=$grpc_node_plugin --grpc_out=$nodejs_pb_dir *.proto
if [ ! -z $jsProtoExec ]; then
# protoc generate js code with grpc_tools_node_protoc
$jsProtoExec --js_out=import_style=commonjs,binary:$nodejs_pb_dir \
--grpc_out=$nodejs_pb_dir --plugin=protoc-gen-grpc=`which grpc_tools_node_protoc_plugin` *.proto
else
grpc_node_plugin=$(which "grpc_node_plugin")
if [ -z $grpc_node_plugin ]; then
echo 'Please install grpc_node_plugin'
exit 0
fi

# protoc generate js code without grpc_tools_node_protoc,but use grpc_node_plugin
$protoExec --js_out=import_style=commonjs,binary:$nodejs_pb_dir --plugin=protoc-gen-grpc=$grpc_node_plugin --grpc_out=$nodejs_pb_dir *.proto
fi

# replace
os=`uname -s`
if [ $os == "Darwin" ];then
# mac os LC_CTYPE config
export LC_CTYPE=C

# mac os
sed -i "" 's/var google_api_annotations_pb/\/\/ var google_api_annotations_pb/g' `grep google_api_annotations_pb -rl $nodejs_pb_dir`
sed -i "" 's/let google_api_annotations_pb/\/\/ let google_api_annotations_pb/g' `grep google_api_annotations_pb -rl $nodejs_pb_dir`
sed -i "" 's/goog.object.extend(proto, google_api_annotations_pb)/\/\/ this code deleted/g' `grep google_api_annotations_pb -rl $nodejs_pb_dir`
Expand Down
File renamed without changes.
9 changes: 3 additions & 6 deletions example/clients/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"devDependencies": {
"grpc-tools": "^1.7.3"
},
"dependencies": {
"google-protobuf": "^3.8.0",
"grpc": "^1.24.3",
"node-pre-gyp": "^0.15.0"
"google-protobuf": "^3.20.1",
"grpc": "^1.24.11",
"grpc-tools": "^1.11.2"
}
}
26 changes: 0 additions & 26 deletions example/clients/nodejs/readme.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
# install nodejs

cd /usr/local/
sudo wget https://nodejs.org/dist/v12.16.2/node-v12.16.2-linux-x64.tar.xz
sudo xz -d node-v12.16.2-linux-x64.tar.xz
sudo tar xvf node-v12.16.2-linux-x64.tar.xz
sudo mv node-v12.16.2-linux-x64 nodejs

For the convenience of the current user, set nodejs to belong to the current user,
which is not recommended in the production environment

sudo chown -R $USER /usr/local/nodejs
sudo ln -s /usr/local/nodejs/bin/npm /usr/bin/npm
sudo chmod +x /usr/bin/npm
vim ~/.bashrc
export NODEJS_HOME=/usr/local/nodejs
export PATH=$NODEJS_HOME/bin:$PATH

source ~/.bashrc

# install cnpm

npm install -g cnpm --registry=https://registry.npm.taobao.org

# nodejs gprc install

cnpm install grpc-tools --save-dev
cnpm install google-protobuf --save
cnpm install grpc --save

or

cnpm install
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/daheige/gmicro

go 1.13
go 1.16

require (
github.com/golang/protobuf v1.5.2
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/prometheus/client_golang v1.11.0
github.com/stretchr/testify v1.7.0
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
google.golang.org/genproto v0.0.0-20210617175327-b9e0b3197ced
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.27.1
github.com/prometheus/client_golang v1.12.2
github.com/stretchr/testify v1.7.1
golang.org/x/net v0.0.0-20220513224357-95641704303c
google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3
google.golang.org/grpc v1.46.2
google.golang.org/protobuf v1.28.0
)
Loading

0 comments on commit b41be51

Please sign in to comment.