This project provides a basic implementation of a gRPC server and client in Go. It demonstrates the following functionality:
- Simple RPC
- Server-side streaming RPC
- Client-side streaming RPC
- Bidirectional streaming RPC
The project directory structure is as follows:
client
: Contains the client implementation and themain.go
file.server
: Contains the server implementation and themain.go
file.proto
: Stores the.proto
file defining the gRPC services and messages.
Before running the gRPC server and client, make sure you have the following prerequisites installed:
- Go (1.16 or later): Installation Guide
- Protocol Buffers Compiler (protoc): Installation Guide
- gRPC Go plugin: Run the following commands to install the plugin:
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
export PATH="$PATH:$(go env GOPATH)/bin"
- Create a new directory for your project and navigate into it:
mkdir server-client-go-grpc
cd server-client-go-grpc
- Initialize a Go module for the project:
go mod init github.com/your_username/server-client-go-grpc
- Install the necessary dependencies:
go mod tidy
- To generate the
.pb.go
files from the.proto
file, use the following command:
protoc --go_out=. --go-grpc_out=. proto/greet.proto
Note: Depending on the path mentioned in your greet.proto file, you may need to adjust the command accordingly.
The server implementation can be found in the server/main.go
file. This file defines the controllers and services used by the server.
The client implementation can be found in the client/main.go
file. This file demonstrates how the client interacts with the server.
- Start the gRPC server:
go run server/main.go
- Run the gRPC client in a separate terminal session:
go run client/main.go
This project is licensed under the MIT License.