This project is a minimal example to help you understand how to work with gRPC in Golang. It demonstrates all four types of gRPC calls: unary, server streaming, client streaming, and bidirectional streaming.
go-grpc/
client/ # gRPC client implementations
server/ # gRPC server implementations
proto/ # Protobuf definitions and generated code
go.mod # Go module definition
go.sum # Go dependencies
- Go 1.23 or newer (download Go)
protocProtocol Buffers compiler (installation guide)protoc-gen-goandprotoc-gen-go-grpcplugins:Ensure yourgo install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
$GOPATH/binis in your$PATH.
- Clone the repository:
git clone https://github.com/csush/go-grpc.git cd go-grpc - Install dependencies:
go mod tidy
- (Optional) Regenerate gRPC code if you modify
proto/greet.proto:protoc --go_out=proto --go-grpc_out=proto proto/greet.proto
In one terminal, start the gRPC server:
cd server
go run main.goThe server listens on localhost:8080 by default.
In another terminal, run the client:
cd client
# Edit main.go to uncomment the call you want to test (unary, server stream, client stream, or bidi stream)
go run main.goSee proto/greet.proto for full service and message definitions.
- Unary RPC:
SayHello(NoParam) returns (HelloResponse) - Server Streaming RPC:
SayHelloServerStreaming(NamesList) returns (stream HelloResponse) - Client Streaming RPC:
SayHelloClientStreaming(stream HelloRequest) returns (MessagesList) - Bidirectional Streaming RPC:
SayHelloBidirectionalStreaming(stream HelloRequest) returns (stream HelloResponse)
- To try different RPC types, edit
client/main.goand uncomment the relevant function call. - You can modify the proto file and regenerate Go code as described above.
This project is for educational purposes and is not production-ready. Contributions and suggestions are welcome!