跳到正文
Skillpedia
API 与服务器(后端)48k · #4791

grpc-golang

它能做什么

这个技能可以帮你用 gRPC 在 Go 中搭建安全、高效的通信服务。它会讲解如何定义程序之间的通信方式、如何保证通信安全(mTLS),以及如何监控运行情况。

适用场景

  • ✓当你要搭建程序之间需要快速且安全地相互通信的系统时。
  • ✓当你要定义软件不同部分之间如何交换信息时。
  • ✓当你要构建对性能和安全性都有较高要求的内部 API 时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/grpc-golang/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/grpc-golang/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我该如何使用 gRPC,在我的 Go 服务之间设置安全通信(mTLS)?”

每周 5 个新技能,1 分钟读完。

工作原理

这个技能会指导你使用 Protobuf 和 Buf 定义通信约定,配置安全机制,确保只有经过授权的服务才能通信(mTLS),并添加工具来监控流量和性能。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

gRPC Golang (gRPC-Go)

Overview

Comprehensive guide for designing and implementing production-grade gRPC services in Go. Covers contract standardization with Buf, transport layer security via mTLS, and deep observability with OpenTelemetry interceptors.

Use this skill when

  • Designing microservices communication with gRPC in Go.
  • Building high-performance internal APIs using Protobuf.
  • Implementing streaming workloads (unidirectional or bidirectional).
  • Standardizing API contracts using Protobuf and Buf.
  • Configuring mTLS for service-to-service authentication.

Do not use this skill when

  • Building pure REST/HTTP public APIs without gRPC requirements.
  • Modifying legacy .proto files without the ability to introduce a new API version (e.g., api.v2) or ensure backward compatibility.
  • Managing service mesh traffic routing (e.g., Istio/Linkerd), which is outside the application code scope.

Step-by-Step Guide

  1. Confirm Technical Context: Identify Go version, gRPC-Go version, and whether the project uses Buf or raw protoc.
  2. Confirm Requirements: Identify mTLS needs, load patterns (unary/streaming), SLOs, and message size limits.
  3. Plan Schema: Define package versioning (e.g., api.v1), resource types, and error mapping.
  4. Security Design: Implement mTLS for service-to-service authentication.
  5. Observability: Configure interceptors for tracing, metrics, and structured logging.
  6. Verification: Always run buf lint and breaking change checks before finalizing code generation.

Refer to resources/implementation-playbook.md for detailed patterns, code examples, and anti-patterns.

Examples

Example 1: Defining a Service & Message (v1 API)

syntax = "proto3";
package api.v1;
option go_package = "github.com/org/repo/gen/api/v1;apiv1";

service UserService {
  rpc GetUser(GetUserRequest) returns (GetUserResponse);
}

message User {
  string id = 1;
  string name = 2;
}

message GetUserRequest {
  string id = 1;
}

message GetUserResponse {
  User user = 1;
}

Best Practices

  • ✅ Do: Use Buf to standardize your toolchain and linting with buf.yaml and buf.gen.yaml.
  • ✅ Do: Always use semantic versioning in package paths (e.g., package api.v1).
  • ✅ Do: Enforce mTLS for all internal service-to-service communication.
  • ✅ Do: Handle ctx.Done() in all streaming handlers to prevent resource leaks.
  • ✅ Do: Map domain errors to standard gRPC status codes (e.g., codes.NotFound).
  • ❌ Don't: Return raw internal error strings or stack traces to gRPC clients.
  • ❌ Don't: Create a new grpc.ClientConn per request; always reuse connections.

Troubleshooting

  • Error: Inconsistent Gen: If the generated code does not match the schema, run buf generate and verify the go_package option.
  • Error: Context Deadline: Check client timeouts and ensure the server is not blocking infinitely in streaming handlers.
  • Error: mTLS Handshake: Ensure the CA certificate is correctly added to the x509.CertPool on both client and server sides.

Limitations

  • Does not cover service mesh traffic routing (Istio/Linkerd configuration).
  • Does not cover gRPC-Web or browser-based gRPC integration.
  • Assumes Go 1.21+ and gRPC-Go v1.60+; older versions may have different APIs (e.g., grpc.Dial vs grpc.NewClient).
  • Does not cover L7 gRPC-aware load balancer configuration (e.g., Envoy, NGINX).
  • Does not address Protobuf schema registry or large-scale schema governance beyond Buf lint.

Resources

Related Skills

  • @golang-pro - General Go patterns and performance optimization outside the gRPC layer.
  • @go-concurrency-patterns - Advanced goroutine lifecycle management for streaming handlers.
  • @api-design-principles - Resource naming and versioning strategy before writing .proto files.
  • @docker-expert - Containerizing gRPC services and configuring TLS cert injection via Docker secrets.
常见问题

什么是 gRPC 和 Protobuf?

gRPC 是程序之间通过网络相互通信的一种方式。Protobuf 是一种用来定义消息结构的语言,可以让通信更加高效。

什么是 mTLS?

mTLS(双向传输层安全)是一种安全机制,它确保客户端和服务器在交换信息前都要互相验证身份,从而防止未经授权的访问。

什么是 Buf?

Buf 是一个帮助管理和规范 Protobuf 消息定义文件的工具,可以确保所有人遵循相同的规则,并简化代码生成。

详情

作者的原始描述

Build production-ready gRPC services in Go with mTLS, streaming, and observability. Use when designing Protobuf contracts with Buf or implementing secure service-to-service transport.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4791
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能