This is an implementation of Udemy tutorial
-
install GO:
$ wget https://dl.google.com/go/go1.12.9.linux-amd64.tar.gz $ sudo tar -C /usr/local -xzf go1.12.9.linux-amd64.tar.gz $ export PATH=$PATH:/usr/local/go/bin
-
Install grpc-go:
$ go get -u google.golang.org/grpc
-
Install Protocol Buffers for GO:
$ go get -u github.com/golang/protobuf/protoc-gen-go
-
Install Protocol Buffers (protoc)
$ curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.9.1/protoc-3.9.1-linux-x86_64.zip $ unzip protoc-3.9.1-linux-x86_64.zip -d protoc3 $ sudo mv protoc3/bin/* /usr/local/bin/ && sudo mv protoc3/include/* /usr/local/include/ $ rm protoc-3.9.1-linux-x86_64.zip && rm -rf protoc3
-
Compile
.proto
file to.go
file:$ protoc greet/greetpb/greet.proto --go_out=plugins=grpc:.
-
Run greet server:
$ go run greet/greet_server/server.go
-
Run greet client:
$ go run greet/greet_client/client.go
-
Compile
.proto
file to.go
file:$ protoc calculator/calculatorpb/calculator.proto --go_out=plugins=grpc:.
-
Run calculator server:
$ go run calculator/calculator_server/server.go
-
Run calculator client:
$ go run calculator/calculator_client/client.go
(Update) How to run Sum
RPC via REST:
-
Download the following packages:
$ 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
-
Compile
.proto
file to.go
file:$ protoc -I/usr/local/include -I. \ -I$GOPATH/src \ -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ --go_out=plugins=grpc:. \ calculator/calculatorpb/calculator.proto
-
Generate reverse-proxy using
protoc-gen-grpc-gateway
:$ protoc -I/usr/local/include -I. \ -I$GOPATH/src \ -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ --grpc-gateway_out=logtostderr=true:. \ calculator/calculatorpb/calculator.proto
It will generate
calculator/calculatorpb/calculator.pb.gw.go
file -
(Optional) Generate swagger definitions using
protoc-gen-swagger
:$ protoc -I/usr/local/include -I. \ -I$GOPATH/src \ -I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ --swagger_out=logtostderr=true:. \ calculator/calculatorpb/calculator.proto
It will generate
calculator/calculatorpb/calculator.swagger.json
file -
Run calculator server:
$ go run calculator/calculator_server/server.go
-
Run calculator gateway:
$ go run calculator/calculator_server/gateway.go
-
Send message via
curl
:$ curl -X POST -k http://127.0.0.1:8081/sum -d '{"first_number": 5, "second_number": 3}'
And you will get response
{"sum_result":8}
as result
-
Install openssl:
$ sudo apt-get install openssl
-
Create needed certificates, keys:
$ cd ssl $ chmod +x ./generate_files.sh $ ./generate_files.sh
if you got
Cannot open file .rnd
error - create an empty.rnd
file
-
Install MongoDB:
-
Download and install MongoDB from here
-
Create folder to store data:
$ mkdir ~/mongodata $ mkdir ~/mongodata/db
-
Run MongoDB:
$ /usr/bin/mongod --dbpath ~/mongodata/db
-
-
Install UI for your MongoDB:
-
Download Robo 3T from here
-
Switch to download directory and run these commands:
$ tar -xvzf robo3t*.tar.gz $ sudo mkdir /usr/local/bin/robomongo $ sudo mv robo3t*/* /usr/local/bin/robomongo $ cd /usr/local/bin/robomongo/bin $ sudo chmod +x robo3t
-
Open .bashrc file:
$ sudo vim ~/.bashrc
And add the following line to the end of the file:
alias robomongo='/usr/local/bin/robomongo/bin/robo3t'
-
Reload it using the following command:
$ source ~/.bashrc
-
Run robomongo from your terminal:
$ robomongo
-
-
Install MongoDB driver for Golang:
$ go get go.mongodb.org/mongo-driver/mongo
-
Compile
.proto
file to.go
file:$ protoc blog/blogpb/blog.proto --go_out=plugins=grpc:.
-
Run blog server:
$ go run blog/blog_server/server.go
-
Run blog client:
$ go run blog/blog_client/client.go