gRPC Calculator – just a simple example of a gRPC service written in Go. You'll find a few standard math operations implemented (Add, Subtract, Multiply, Divide), and it's all wrapped up with some middleware for logging and recovery
https://github.com/vshulcz/grpc-protos
-
Clone the repo:
git clone https://github.com/vshulcz/grpc-calculator.git cd grpc-calculator
-
Install dependencies:
go mod tidy
-
Compile the project:
go build -o calculator ./cmd/calculator
-
Run the gRPC server:
./calculator --config="config/dev.yaml"
-
Test it out with grpcurl: Install grpcurl:
brew install grpcurl
To see the available services:
grpcurl -plaintext localhost:5105 list
To call the
Add
method:grpcurl -plaintext -d '{"number1": 5, "number2": 3}' localhost:5105 calculator.Calculator.Add
-
Run the tests:
go test ./... -v
The configuration is stored in YAML files (e.g., config/dev.yaml
), and we load it using cleanenv
.