grpc-golisted
Install: claude install-skill omeyang/Thoth
# Go gRPC 专家
使用 Go gRPC 开发高性能 RPC 服务:$ARGUMENTS
---
## 1. 服务定义
### Proto 文件
使用版本化包名,请求/响应独立 message,使用 google.protobuf 标准类型。
```protobuf
syntax = "proto3";
package user.v1;
option go_package = "github.com/example/api/user/v1;userv1";
service UserService {
rpc GetUser(GetUserRequest) returns (GetUserResponse); // Unary
rpc ListUsers(ListUsersRequest) returns (stream User); // Server streaming
rpc BatchCreateUsers(stream CreateUserRequest) returns (BatchCreateUsersResponse); // Client streaming
rpc Chat(stream ChatMessage) returns (stream ChatMessage); // Bidirectional
}
```
> 完整 Proto 定义和代码生成命令见 [references/examples.md](references/examples.md#proto-文件完整定义)
### 生成代码
```bash
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
api/user/v1/*.proto
```
---
## 2. 服务端实现
### 核心结构
```go
type UserServer struct {
userv1.UnimplementedUserServiceServer
repo UserRepository
}
```
### RPC 类型签名
| RPC 类型 | 签名 |
|---------|------|
| Unary | `GetUser(ctx, *GetUserRequest) (*GetUserResponse, error)` |
| Server Stream | `ListUsers(*ListUsersRequest, UserService_ListUsersServer) error` |
| Client Stream | `BatchCreateUsers(UserService_BatchCreateUsersServer) error` |
| Bidi Stream | `Chat(UserService_ChatServer) error` |
> 完整四种 RPC 实现见 [references/examples.md](references/examples.md#服务端实现)
### 启动服务(含拦截器链)
```go
server := grpc.NewServer(
grpc.ChainUnaryInterceptor(