This is simple demonstration of how grpc is to be used with golang.
- Download and install protoc form below link:
https://github.com/protocolbuffers/protobuf/releases
- Next, install Go support for Google’s protocol buffers and grpc:
go get -u github.com/golang/protobuf/protoc-gen-go
go install github.com/golang/protobuf/protoc-gen-go
go get google.golang.org/grpc
- Unary gRPC is explained with example of addition and subtraction example.You will find the example inside SimpleGRPC directory. For simple/unary grpc sample.pb.go file is generated by executing following command:
protoc -I SimpleGRPC/ProtoDir/ ./SimpleGRPC/ProtoDir/sample.proto --go_out=plugins=grpc:SimpleGRPC/ProtoDir/
- Server Side Streaming type of grpc is explained with the help of small example of finding Divisors of number.It is present under ServerSideStreaming directory. For server side streaming grpc serverStreamingProto.pb.go file is generated by executing following command:
protoc -I ServerSideStreaming/ServerSideStreamingProto/ ./ServerSideStreaming/ServerSideStreamingProto/serverStreamingProto.proto --go_out=plugins=grpc:ServerSideStreaming/ServerSideStreamingProto/
- Client Side Streaming type of grpc is explained with the help of small example of finding max number from stream of number.The example is present under ClientSideStramingGRPC directory. For client side streaming grpc clientstraming.pb.go file is generated by executing following command:
protoc -I ClientSideStramingGRPC/ClientSideStramingProto/ ./ClientSideStramingGRPC/ClientSideStramingProto/clientstraming.proto --go_out=plugins=grpc:ClientSideStramingGRPC/ClientSideStramingProto/
- Bidirectional Streaming type of grpc is explained with the help of small example of finding max number from stream of number.The example is present under BiDirectionGRPC directory. For bidirectional streaming grpc bidirctionalProto.pb.go file is generated by executing following command:
protoc -I BiDirectionGRPC/BiDirProto/ ./BiDirectionGRPC/BiDirProto/bidirctionalProto.proto --go_out=plugins=grpc:BiDirectionGRPC/BiDirProto/