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 calculatorTo generate the SSL certificates, you need to run the following command:
cd ssl && chmod +x ssl.sh && ./ssl.shYou 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/serverYou will do the same for the calculator server if you want to run it:
./bin/calculator/serverTo run the client, you need to run the following command:
./bin/greet/clientYou will do the same for the calculator client if you want to run it:
./bin/calculator/clientOn 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.gzYou need to move the evans to the /usr/local/bin directory.
sudo mv evans /usr/local/binAfter that, you need run calculator server:
make calculator && ./bin/calculator/serverYou 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 50051You 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 calculatorYou need to select the service:
service CalculatorServiceYou can call the Add method:
call AddAfter 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:
exitYou can do the same for all services and methods.
To run MongoDB, you need to run the following command:
docker-compose up -dYou need to generate the gRPC code:
make blogYou need to run the server:
./bin/blog/serverYou can run the client:
./bin/blog/clientThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.