This project helps you in understanding gRPC based concepts and it's implementation
NOTE : Keep all proto files in $GOPATH/protofiles under their project names directory (best practices)
mkdir $GOPATH/protofiles
mkdir $GOPATH/protoFiles/grpc_tutorial
https://github.com/amulyakashyap09/golang_grpc/blob/master/users.proto to $GOPATH/protoFiles/grpc_tutorial
protoc -I /protofiles /protofiles/grpc_tutorial/users.proto --gout=plugins=./grpc_tutorial
- Above command will generate the grpc_tutorial named directory under $GOPATH/src
- With nested folder name pb which contains a file named users.pb.go
- This file is generated by proto compiler
cd $GOPATH/src/grpc_tutorial
mkdir client server
touch client/main.go server/main.go server/data.go
Now you have your project strcuture ready.
- https://github.com/amulyakashyap09/golang_grpc/blob/master/client/main.go to dir named client
- https://github.com/amulyakashyap09/golang_grpc/blob/master/server/main.go to dir named server
- https://github.com/amulyakashyap09/golang_grpc/blob/master/server/data.go to dir named server
Now we are done with project and its content.
Build the server :
go install grpc_tutorial/server
Execute the server binary :
$GOPATH/bin/server
Build the client :
go install grpc_tutorial/client
Execute the client binary :
$GOPATH/bin/client -o <int_value>
with options
- 1 sending metadata to server |
$GOPATH/bin/client -o 1
- 2 Fetching User by ID |
$GOPATH/bin/client -o 2
- 3 Fetch all users |
$GOPATH/bin/client -o 3
- 4 Save user to file |
$GOPATH/bin/client -o 4
- 5 Save all users to file |
$GOPATH/bin/client -o 5
And you'll see output everytime on the terminal when any command executes.
- 0.0.1 | basic implementation of gRPC in golang
- Amulya Kasyap ([email protected])