gRPC
- Raw Implementation
Code Source: https://github.com/gogf/examples/tree/main/grpc/rawgrpc
Description
This example demonstrates how to implement raw gRPC
services in GoFrame
without additional abstractions. It shows how to:
- Create raw
gRPC
servers and clients - Use protocol buffers directly
- Implement service handlers
- Make direct
RPC
calls
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 checksums
Features
The example showcases the following features:
-
Raw
gRPC
Implementation- Direct protocol buffer usage
- Manual service implementation
- Basic
RPC
communication - Error handling
-
Client Usage
- Direct connection management
- Raw
RPC
calls - 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:. *.proto -
Start the server:
cd server
go run server.go -
Run the client:
cd client
go run client.go
Implementation Details
The example demonstrates:
- Raw
gRPC
service implementation - Direct client/server usage