docs: add AI-Native Development section to README (#5333)

This commit is contained in:
Kevin Wan
2025-12-12 22:28:47 +08:00
committed by GitHub
parent 3d291328d8
commit 6bd0d169d5
2 changed files with 229 additions and 33 deletions

View File

@@ -17,7 +17,7 @@
<a href="https://trendshift.io/repositories/3263" target="_blank"><img src="https://trendshift.io/api/badge/repositories/3263" alt="zeromicro%2Fgo-zero | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a> <a href="https://trendshift.io/repositories/3263" target="_blank"><img src="https://trendshift.io/api/badge/repositories/3263" alt="zeromicro%2Fgo-zero | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
<a href="https://www.producthunt.com/posts/go-zero?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-go&#0045;zero" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=334030&theme=light" alt="go&#0045;zero - A&#0032;web&#0032;&#0038;&#0032;rpc&#0032;framework&#0032;written&#0032;in&#0032;Go&#0046; | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a> <a href="https://www.producthunt.com/posts/go-zero?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-go&#0045;zero" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=334030&theme=light" alt="go&#0045;zero - A&#0032;web&#0032;&#0038;&#0032;rpc&#0032;framework&#0032;written&#0032;in&#0032;Go&#0046; | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
## 0. go-zero 介绍 ## go-zero 介绍
go-zero收录于 CNCF 云原生技术全景图:[https://landscape.cncf.io/?selected=go-zero](https://landscape.cncf.io/?selected=go-zero))是一个集成了各种工程实践的 web 和 rpc 框架。通过弹性设计保障了大并发服务端的稳定性,经受了充分的实战检验。 go-zero收录于 CNCF 云原生技术全景图:[https://landscape.cncf.io/?selected=go-zero](https://landscape.cncf.io/?selected=go-zero))是一个集成了各种工程实践的 web 和 rpc 框架。通过弹性设计保障了大并发服务端的稳定性,经受了充分的实战检验。
@@ -34,7 +34,7 @@ go-zero 包含极简的 API 定义和生成工具 goctl可以根据定义的
![架构图](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/architecture.png) ![架构图](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/architecture.png)
## 1. go-zero 框架背景 ## go-zero 框架背景
18 年初,我们决定从 `Java+MongoDB` 的单体架构迁移到微服务架构,经过仔细思考和对比,我们决定: 18 年初,我们决定从 `Java+MongoDB` 的单体架构迁移到微服务架构,经过仔细思考和对比,我们决定:
@@ -49,7 +49,7 @@ go-zero 包含极简的 API 定义和生成工具 goctl可以根据定义的
* 需要有更快速的问题定位能力 * 需要有更快速的问题定位能力
* 更便捷的增加新特性 * 更便捷的增加新特性
## 2. go-zero 框架设计思考 ## go-zero 框架设计思考
对于微服务框架的设计,我们期望保障微服务稳定性的同时,也要特别注重研发效率。所以设计之初,我们就有如下一些准则: 对于微服务框架的设计,我们期望保障微服务稳定性的同时,也要特别注重研发效率。所以设计之初,我们就有如下一些准则:
@@ -62,7 +62,7 @@ go-zero 包含极简的 API 定义和生成工具 goctl可以根据定义的
我们经历不到半年时间,彻底完成了从 `Java+MongoDB``Golang+MySQL` 为主的微服务体系迁移,并于 18 年 8 月底完全上线,稳定保障了业务后续迅速增长,确保了整个服务的高可用。 我们经历不到半年时间,彻底完成了从 `Java+MongoDB``Golang+MySQL` 为主的微服务体系迁移,并于 18 年 8 月底完全上线,稳定保障了业务后续迅速增长,确保了整个服务的高可用。
## 3. go-zero 项目实现和特点 ## go-zero 项目实现和特点
go-zero 是一个集成了各种工程实践的包含 web 和 rpc 框架,有如下主要特点: go-zero 是一个集成了各种工程实践的包含 web 和 rpc 框架,有如下主要特点:
@@ -84,13 +84,13 @@ go-zero 是一个集成了各种工程实践的包含 web 和 rpc 框架,有
![弹性设计](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/resilience.jpg) ![弹性设计](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/resilience.jpg)
## 4. 我们使用 go-zero 的基本架构图 ## 我们使用 go-zero 的基本架构图
<img width="1067" alt="image" src="https://user-images.githubusercontent.com/1918356/171880582-11a86658-41c3-466c-95e7-7b1220eecc52.png"> <img width="1067" alt="image" src="https://user-images.githubusercontent.com/1918356/171880582-11a86658-41c3-466c-95e7-7b1220eecc52.png">
觉得不错的话,别忘 **star** 👏 觉得不错的话,别忘 **star** 👏
## 5. Installation ## Installation
在项目目录下通过如下命令安装: 在项目目录下通过如下命令安装:
@@ -98,7 +98,108 @@ go-zero 是一个集成了各种工程实践的包含 web 和 rpc 框架,有
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/zeromicro/go-zero GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/zeromicro/go-zero
``` ```
## 6. Quick Start ## AI 原生开发
让大模型成为你的 go-zero 专家go-zero 团队构建了完整的 AI 工具生态,包括 **ai-context**、**zero-skills** 和 **mcp-zero** 三个项目,让 Claude、GitHub Copilot、Cursor 等 AI 编程助手生成符合 go-zero 规范的代码。
### 三大核心项目
**[ai-context](https://github.com/zeromicro/ai-context)** - AI 的"工作手册"~5KB
- 告诉 AI 助手**什么时候做什么**
- 工作流程和决策树的快速参考
- 专为 GitHub Copilot 优化(通过 `.github/copilot-instructions.md`
**[zero-skills](https://github.com/zeromicro/zero-skills)** - AI 的"技术百科"~40KB+
- 提供**详细模式**和完整示例
- ✅ 正确做法 vs ❌ 错误做法对比
- 涵盖 REST API、RPC、数据库、弹性保护等
**[mcp-zero](https://github.com/zeromicro/mcp-zero)** - AI 的"实时助手"
- 让 AI 能**真正动手做**:生成代码、分析项目
- 基于 Model Context Protocol (MCP)
- 与 Claude Desktop 深度集成
### 快速配置
#### GitHub Copilot
```bash
# 添加 ai-context 作为 submodule
git submodule add https://github.com/zeromicro/ai-context.git .github/ai-context
# 创建符号链接macOS/Linux
ln -s ai-context/00-instructions.md .github/copilot-instructions.md
# Windows 用户使用
mklink .github\copilot-instructions.md .github\ai-context\00-instructions.md
# 更新到最新版本
git submodule update --remote .github/ai-context
```
#### Cursor
```bash
# 添加 ai-context 作为 submodule
git submodule add https://github.com/zeromicro/ai-context.git .cursorrules
# 更新到最新版本
git submodule update --remote .cursorrules
```
#### Windsurf (Codeium)
```bash
# 添加 ai-context 作为 submodule
git submodule add https://github.com/zeromicro/ai-context.git .windsurfrules
# 更新到最新版本
git submodule update --remote .windsurfrules
```
#### Claude Desktop + mcp-zero
```bash
# 安装 mcp-zero
git clone https://github.com/zeromicro/mcp-zero.git
cd mcp-zero
go build -o mcp-zero main.go
# 配置 Claude DesktopmacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
# 在 mcpServers 中添加:
{
"mcpServers": {
"mcp-zero": {
"command": "/path/to/mcp-zero",
"env": {
"GOCTL_PATH": "/Users/yourname/go/bin/goctl"
}
}
}
}
```
或使用 Claude 命令行:
```bash
# 通过 CLI 添加 mcp-zero 服务器
claude mcp add \
--transport stdio \
mcp-zero \
--env GOCTL_PATH=/Users/yourname/go/bin/goctl \
-- /path/to/mcp-zero
```
### 协同工作原理
AI 助手通过这三个工具协同配合,提供完整的开发体验:
1. **ai-context** 提供工作流程指导和快速模式
2. **zero-skills** 提供详细实现和最佳实践
3. **mcp-zero** 提供实时代码生成和项目分析
**示例**:创建新的 REST API
- AI 读取 **ai-context** → 了解应该用 `create_api_service` 工具
- AI 调用 **mcp-zero** → 执行生成项目结构
- AI 参考 **zero-skills** → 获取完整的 Handler/Logic/Context 三层架构模式
- 结果:符合 go-zero 规范的生产级代码 ✅
## Quick Start
0. 完整示例请查看 0. 完整示例请查看
@@ -113,18 +214,18 @@ GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/zeromicro
```shell ```shell
# Go # Go
GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest
# For Mac # For Mac
brew install goctl brew install goctl
# docker for all platforms # docker for all platforms
docker pull kevinwan/goctl docker pull kevinwan/goctl
# run goctl # run goctl
docker run --rm -it -v `pwd`:/app kevinwan/goctl --help docker run --rm -it -v `pwd`:/app kevinwan/goctl --help
``` ```
确保 goctl 可执行,并且在 $PATH 环境变量里。 确保 goctl 可执行,并且在 $PATH 环境变量里。
2. 快速生成 api 服务 2. 快速生成 api 服务
```shell ```shell
@@ -165,13 +266,13 @@ GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/zeromicro
... ...
``` ```
## 7. Benchmark ## Benchmark
![benchmark](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/benchmark.png) ![benchmark](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/benchmark.png)
[测试代码见这里](https://github.com/smallnest/go-web-framework-benchmark) [测试代码见这里](https://github.com/smallnest/go-web-framework-benchmark)
## 8. 文档 ## 文档
* API 文档 * API 文档
@@ -192,7 +293,7 @@ GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/zeromicro
| [goctl-android](https://github.com/zeromicro/goctl-android) | 生成 `java (android)` 端 `http client` 请求代码 | | [goctl-android](https://github.com/zeromicro/goctl-android) | 生成 `java (android)` 端 `http client` 请求代码 |
| [goctl-go-compact](https://github.com/zeromicro/goctl-go-compact) | 合并 `api` 里同一个 `group` 里的 `handler` 到一个 `go` 文件 | | [goctl-go-compact](https://github.com/zeromicro/goctl-go-compact) | 合并 `api` 里同一个 `group` 里的 `handler` 到一个 `go` 文件 |
## 9. go-zero 用户 ## go-zero 用户
go-zero 已被许多公司用于生产部署,接入场景如在线教育、电商业务、游戏、区块链等,目前为止,已使用 go-zero 的公司包括但不限于: go-zero 已被许多公司用于生产部署,接入场景如在线教育、电商业务、游戏、区块链等,目前为止,已使用 go-zero 的公司包括但不限于:
@@ -311,7 +412,7 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
如果贵公司也已使用 go-zero欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。 如果贵公司也已使用 go-zero欢迎在 [登记地址](https://github.com/zeromicro/go-zero/issues/602) 登记,仅仅为了推广,不做其它用途。
## 10. CNCF 云原生技术全景图 ## CNCF 云原生技术全景图
<p float="left"> <p float="left">
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-logo.svg" width="200"/>&nbsp;&nbsp;&nbsp; <img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-logo.svg" width="200"/>&nbsp;&nbsp;&nbsp;
@@ -320,13 +421,13 @@ go-zero 已被许多公司用于生产部署,接入场景如在线教育、电
go-zero 收录在 [CNCF Cloud Native 云原生技术全景图](https://landscape.cncf.io/?selected=go-zero)。 go-zero 收录在 [CNCF Cloud Native 云原生技术全景图](https://landscape.cncf.io/?selected=go-zero)。
## 11. 微信公众号 ## 微信公众号
`go-zero` 相关文章和视频都会在 `微服务实践` 公众号整理呈现,欢迎扫码关注 👏 `go-zero` 相关文章和视频都会在 `微服务实践` 公众号整理呈现,欢迎扫码关注 👏
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/zeromicro.jpg" alt="wechat" width="600" /> <img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/zeromicro.jpg" alt="wechat" width="600" />
## 12. 微信交流群 ## 微信交流群
如果文档中未能覆盖的任何疑问,欢迎您在群里提出,我们会尽快答复。 如果文档中未能覆盖的任何疑问,欢迎您在群里提出,我们会尽快答复。
@@ -336,10 +437,4 @@ go-zero 收录在 [CNCF Cloud Native 云原生技术全景图](https://landscape
加群之前有劳点一下 ***star***,一个小小的 ***star*** 是作者们回答海量问题的动力!🤝 加群之前有劳点一下 ***star***,一个小小的 ***star*** 是作者们回答海量问题的动力!🤝
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/wechat.jpg" alt="wechat" width="300" /> <img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/wechat.jpg" alt="wechat" width="300" />
## 13. 知识星球
官方团队运营的知识星球
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/zsxq.jpg" alt="知识星球" width="300" />

119
readme.md
View File

@@ -92,11 +92,11 @@ As below, go-zero protects the system with a couple of layers and mechanisms:
![Resilience](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/resilience-en.png) ![Resilience](https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/resilience-en.png)
## The simplified architecture that we use with go-zero ## The simplified architecture that we use with go-zero
<img width="1067" alt="image" src="https://user-images.githubusercontent.com/1918356/171880372-5010d846-e8b1-4942-8fe2-e2bbb584f762.png"> <img width="1067" alt="image" src="https://user-images.githubusercontent.com/1918356/171880372-5010d846-e8b1-4942-8fe2-e2bbb584f762.png">
## Installation ## Installation
Run the following command under your project: Run the following command under your project:
@@ -104,7 +104,108 @@ Run the following command under your project:
go get -u github.com/zeromicro/go-zero go get -u github.com/zeromicro/go-zero
``` ```
## Quick Start ## AI-Native Development
Make AI assistants (Claude, GitHub Copilot, Cursor, etc.) your go-zero experts! The go-zero team provides a complete AI tooling ecosystem to generate framework-compliant code and boost your productivity.
### Three Core Projects
**[ai-context](https://github.com/zeromicro/ai-context)** - AI's "Workflow Guide" (~5KB)
- Tells AI assistants **when and how** to use go-zero tools
- Quick reference for code patterns and decision trees
- Optimized for GitHub Copilot via `.github/copilot-instructions.md`
**[zero-skills](https://github.com/zeromicro/zero-skills)** - AI's "Knowledge Base" (~40KB+)
- Provides **detailed patterns** with complete examples
- Shows ✅ correct patterns vs ❌ common mistakes
- Covers REST APIs, RPC, databases, and resilience patterns
**[mcp-zero](https://github.com/zeromicro/mcp-zero)** - AI's "Runtime Tools"
- Enables AI to **execute actions**: generate code, analyze projects
- Based on Model Context Protocol (MCP)
- Deep integration with Claude Desktop
### Quick Setup
#### GitHub Copilot
```bash
# Add ai-context as a submodule
git submodule add https://github.com/zeromicro/ai-context.git .github/ai-context
# Create symbolic link (macOS/Linux)
ln -s ai-context/00-instructions.md .github/copilot-instructions.md
# Windows
mklink .github\copilot-instructions.md .github\ai-context\00-instructions.md
# Update to latest version
git submodule update --remote .github/ai-context
```
#### Cursor
```bash
# Add ai-context as project rules
git submodule add https://github.com/zeromicro/ai-context.git .cursorrules
# Update to latest
git submodule update --remote .cursorrules
```
#### Windsurf (Codeium)
```bash
# Add ai-context for Windsurf
git submodule add https://github.com/zeromicro/ai-context.git .windsurfrules
# Update to latest
git submodule update --remote .windsurfrules
```
#### Claude Desktop + mcp-zero
```bash
# Install mcp-zero
git clone https://github.com/zeromicro/mcp-zero.git
cd mcp-zero
go build -o mcp-zero main.go
# Configure Claude Desktop (macOS: ~/Library/Application Support/Claude/claude_desktop_config.json)
# Add to mcpServers:
{
"mcpServers": {
"mcp-zero": {
"command": "/path/to/mcp-zero",
"env": {
"GOCTL_PATH": "/Users/yourname/go/bin/goctl"
}
}
}
}
```
Or use Claude CLI:
```bash
# Add mcp-zero server via CLI
claude mcp add \
--transport stdio \
mcp-zero \
--env GOCTL_PATH=/Users/yourname/go/bin/goctl \
-- /path/to/mcp-zero
```
### How It Works
AI assistants use these tools together for a complete development experience:
1. **ai-context** provides workflow guidance and quick patterns
2. **zero-skills** supplies detailed implementations and best practices
3. **mcp-zero** enables real-time code generation and project analysis
**Example**: Creating a new REST API
- AI reads **ai-context** → knows to use `create_api_service` tool
- AI calls **mcp-zero** → generates project structure
- AI references **zero-skills** → implements handlers with correct patterns
- Result: Production-ready code following go-zero conventions ✅
## Quick Start
1. Full examples can be checked out from below: 1. Full examples can be checked out from below:
@@ -119,18 +220,18 @@ go get -u github.com/zeromicro/go-zero
```shell ```shell
# for Go # for Go
go install github.com/zeromicro/go-zero/tools/goctl@latest go install github.com/zeromicro/go-zero/tools/goctl@latest
# For Mac # For Mac
brew install goctl brew install goctl
# docker for all platforms # docker for all platforms
docker pull kevinwan/goctl docker pull kevinwan/goctl
# run goctl # run goctl
docker run --rm -it -v `pwd`:/app kevinwan/goctl --help docker run --rm -it -v `pwd`:/app kevinwan/goctl --help
``` ```
make sure goctl is executable and in your $PATH. make sure goctl is executable and in your $PATH.
3. Create the API file, like greet.api, you can install the plugin of goctl in vs code, api syntax is supported. 3. Create the API file, like greet.api, you can install the plugin of goctl in vs code, api syntax is supported.
```go ```go
@@ -234,11 +335,11 @@ go get -u github.com/zeromicro/go-zero
* [Rapid development of microservice systems - multiple RPCs](https://github.com/zeromicro/zero-doc/blob/main/docs/zero/bookstore-en.md) * [Rapid development of microservice systems - multiple RPCs](https://github.com/zeromicro/zero-doc/blob/main/docs/zero/bookstore-en.md)
* [Examples](https://github.com/zeromicro/zero-examples) * [Examples](https://github.com/zeromicro/zero-examples)
## Chat group ## Chat group
Join the chat via https://discord.gg/4JQvC5A4Fe Join the chat via https://discord.gg/4JQvC5A4Fe
## Cloud Native Landscape ## Cloud Native Landscape
<p float="left"> <p float="left">
<img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-logo.svg" width="200"/>&nbsp;&nbsp;&nbsp; <img src="https://raw.githubusercontent.com/zeromicro/zero-doc/main/doc/images/cncf-logo.svg" width="200"/>&nbsp;&nbsp;&nbsp;