amitbasuri / sample-calculator-grpc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sample gRPC client and server

System Requirements

Building the App

Go

Compile Protobuf

protoc

Example Usage

Run Server

go build  -o ./bin/server ./cmd/server
./bin/server

Run Client

%  go build  -o ./bin/client ./cmd/client
%  ./bin/client -method add -a 5 -b 6
2022/06/11 16:55:51 result: 11
%  ./bin/client -method sub -a 5 -b 6
2022/06/11 16:56:05 result: -1
%  ./bin/client -method mul -a 2 -b 6
2022/06/11 16:56:16 result: 12
%  ./bin/client -method mul -a 22 -b 3
2022/06/11 16:56:32 result: 66
%  ./bin/client -method mul -a 2 -b 0 
2022/06/11 16:56:39 result: 0
%  ./bin/client -method div -a 2 -b 0
2022/06/11 16:56:53 rpc error: code = InvalidArgument desc = cannot divide by zero
%  ./bin/client -method div -a 20 -b 3
2022/06/11 16:57:00 result: 6

Compile proto file

  protoc --go_out=. \
    --go-grpc_out=. \
    api/calculator.proto
   

About


Languages

Language:Go 100.0%