gRPC - Raw Implementation
Description
This example demonstrates how to implement raw gRPC services in GoFrame without additional abstractions. It shows how to:
- Create raw
gRPCservers and clients - Use protocol buffers directly
- Implement service handlers
- Make direct
RPCcalls
Structure
.
├── client/ # Client example
│ └── client.go # Raw gRPC client implementation
├── helloworld/ # Protocol buffer definitions
│ └── helloworld.proto # Service and message definitions
├── server/ # Server example
│ └── server.go # Raw gRPC server implementation
├── go.mod # Go module file
└── go.sum # Go module checksumsFeatures
The example showcases the following features:
Raw
gRPCImplementation- Direct protocol buffer usage
- Manual service implementation
- Basic
RPCcommunication - Error handling
Client Usage
- Direct connection management
- Raw
RPCcalls - Basic error handling
- Connection configuration
Server Features
- Raw service implementation
- Request processing
- Response handling
- Basic configuration
Requirements
Prerequisites
- Protocol buffer compiler installed:
# For macOS brew install protobuf # Install protoc-gen-go and protoc-gen-go-grpc go install google.golang.org/protobuf/cmd/protoc-gen-go@latest go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Usage
Generate protocol buffer code:
cd helloworld protoc --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. *.protoStart the server:
cd server go run server.goRun the client:
cd client go run client.go
Implementation Details
The example demonstrates:
- Raw
gRPCservice implementation - Direct client/server usage