← ClaudeAtlas

grpc-golisted

Go gRPC 专家 - 服务定义(Proto)、Unary/Stream RPC、拦截器(日志/认证/恢复/限流/租户/追踪)、错误处理与错误码映射、元数据传播、负载均衡、健康检查、优雅关闭。适用:微服务通信、API 网关、内部服务间调用、流式数据传输。不适用:浏览器直连(用 gRPC-Web 或 REST);简单 CRUD API(REST 更轻量);消息队列场景(用 Kafka/Pulsar)。触发词:grpc, gRPC, protobuf, proto, 拦截器, interceptor, streaming, 流式, metadata, 元数据, service-config
omeyang/Thoth · ★ 0 · AI & Automation · score 73
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(