Implementing simple examples of gRPC in Golang.
First, you need to install the protocol buffer compiler (protoc) and the Go plugin for the protocol buffer compiler, you can follow the instructions here.
To generate the gRPC code, you need to run the following command:
make greet && make calculator
To generate the SSL certificates, you need to run the following command:
cd ssl && chmod +x ssl.sh && ./ssl.sh
You must configure the environment variables in the .env
file. Example:
ENABLE_TLS=true
CERT_FILE_PATH="ssl/server.crt"
KEY_FILE_PATH="ssl/server.pem"
CERT_CLIENT_FILE_PATH="ssl/ca.crt"
If you want to disable TLS, you must set the ENABLE_TLS
variable to false
.
To run the server, you need to run the following command:
./bin/greet/server
You will do the same for the calculator server if you want to run it:
./bin/calculator/server
To run the client, you need to run the following command:
./bin/greet/client
You will do the same for the calculator client if you want to run it:
./bin/calculator/client
On main.go client files, you can uncomment or comment the lines about the example you want to run.
First of all, you need to install the Evans CLI, you can download the tar.gz file here:
tar -xf evans_file_name.tar.gz
You need to move the evans
to the /usr/local/bin
directory.
sudo mv evans /usr/local/bin
After that, you need run calculator server:
make calculator && ./bin/calculator/server
You can use the Evans CLI to interact with the gRPC server. To do this, you need to run the following command:
evans -r repl --host localhost --port 50051
You need to select the calculator.proto
file and the calculator
service. For that, you need to run the following command on the Evans CLI:
package calculator
You need to select the service:
service CalculatorService
You can call the Add
method:
call Add
After that, the Evans CLI will ask you to enter the first_number
and second_number
values. You can enter the values and press Enter
.
When you finish, you can exit the Evans CLI:
exit
You can do the same for all services and methods.
To run MongoDB, you need to run the following command:
docker-compose up -d
You need to generate the gRPC code:
make blog
You need to run the server:
./bin/blog/server
You can run the client:
./bin/blog/client
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.