make chinese readme as default

master
kevin 4 years ago
parent 520f4d7c1b
commit ff7c14c6b6

@ -0,0 +1,206 @@
English | [简体中文](readme.md)
# go-zero
[![Go](https://github.com/tal-tech/go-zero/workflows/Go/badge.svg?branch=master)](https://github.com/tal-tech/go-zero/actions)
[![codecov](https://codecov.io/gh/tal-tech/go-zero/branch/master/graph/badge.svg)](https://codecov.io/gh/tal-tech/go-zero)
[![Go Report Card](https://goreportcard.com/badge/github.com/tal-tech/go-zero)](https://goreportcard.com/report/github.com/tal-tech/go-zero)
[![Release](https://img.shields.io/github/v/release/tal-tech/go-zero.svg?style=flat-square)](https://github.com/tal-tech/go-zero)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
## 0. what is go-zero?
go-zero is a web and rpc framework that with lots of engineering practices builtin. Its born to ensure the stability of the busy services with resilience design, and has been serving sites with tens of millions users for years.
go-zero contains simple API description syntax and code generation tool called `goctl`. You can generate Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript from .api files with `goctl`.
Advantages of go-zero:
* improve the stability of the services with tens of millions of daily active users
* builtin chained timeout control, concurrency control, rate limit, adaptive circuit breaker, adaptive load shedding, even no configuration needed
* builtin middlewares also can be integrated into your frameworks
* simple API syntax, one command to generate couple different languages
* auto validate the request parameters from clients
* plenty of builtin microservice management and concurrent toolkits
<img src="doc/images/architecture-en.png" alt="Architecture" width="1500" />
## 1. Backgrounds of go-zero
At the beginning of 2018, we heavily suffered from frequent downtime. We decided to re-design our system, from monolithic architecture with Java+MongoDB to microservice architecture. After researches and comparison, we chose to:
* Golang based
* great performance
* simple syntax
* proven engineering efficiency
* extreme deployment experience
* less server resource consumption
* Self-designed microservice architecture
* I have rich experience on designing microservice architectures
* easy to location the problems
* easy to extend the features
## 2. Design considerations on go-zero
By designing the microservice architecture, we expected to ensure the stability, as well as the productivity. And from just the beginning, we have the following design principles:
* keep it simple
* high availability
* stable on high concurrency
* easy to extend
* resilience design, failure-oriented programming
* try best to be friendly to the business logic development, encapsulate the complexity
* one thing, one way
After almost half a year, we finished the transfer from monolithic system to microservice system, and deployed on August 2018. The new system guaranteed the business growth, and the system stability.
## 3. The implementation and features of go-zero
go-zero is a web and rpc framework that integrates lots of engineering practices. The features are mainly listed below:
* powerful tool included, less code to write
* simple interfaces
* fully compatible with net/http
* middlewares are supported, easy to extend
* high performance
* failure-oriented programming, resilience design
* builtin service discovery, load balancing
* builtin concurrency control, adaptive circuit breaker, adaptive load shedding, auto trigger, auto recover
* auto validation of API request parameters
* chained timeout control
* auto management of data caching
* call tracing, metrics and monitoring
* high concurrency protected
As below, go-zero protects the system with couple layers and mechanisms:
![Resilience](doc/images/resilience-en.png)
## 4. Future development plans of go-zero
* auto generate API mock server, make the client debugging eaisier
* auto generate the simple integration test for the server side just from the .api files
## 5. Installation
Run the following command under your project:
```shell
go get -u github.com/tal-tech/go-zero
```
## 6. Quick Start
0. full examples can be checked out from below:
[Rapid development of microservice systems](doc/shorturl-en.md)
[Rapid development of microservice systems - multiple RPCs](doc/bookstore-en.md)
1. install goctl
`goctl`can be read as `go control`. `goctl means not to be controlled by code, instead, we control it. The inside `go` is not `golang`. At the very beginning, I was expecting it to help us improve the productivity, and make our lives easier.
```shell
GO111MODULE=on go get -u github.com/tal-tech/go-zero/tools/goctl
```
make sure goctl is executable.
2. create the API file, like greet.api, you can install the plugin of goctl in vs code, api syntax is supported.
```go
type Request struct {
Name string `path:"name,options=you|me"` // parameters are auto validated
}
type Response struct {
Message string `json:"message"`
}
service greet-api {
@server(
handler: GreetHandler
)
get /greet/from/:name(Request) returns (Response);
}
```
the .api files also can be generate by goctl, like below:
```shell
goctl api -o greet.api
```
3. generate the go server side code
```shell
goctl api go -api greet.api -dir greet
```
the generated files look like:
```
├── greet
│   ├── etc
│   │   └── greet-api.yaml // configuration file
│   ├── greet.go // main file
│   └── internal
│   ├── config
│   │   └── config.go // configuration definition
│   ├── handler
│   │   ├── greethandler.go // get/put/post/delete routes are defined here
│   │   └── routes.go // routes list
│   ├── logic
│   │   └── greetlogic.go // request logic can be written here
│   ├── svc
│   │   └── servicecontext.go // service context, mysql/redis can be passed in here
│   └── types
│   └── types.go // request/response defined here
└── greet.api // api description file
```
the generated code can be run directly:
```shell
cd greet
go run greet.go -f etc/greet-api.yaml
```
by default, its listening on port 8888, while it can be changed in configuration file.
you can check it by curl:
```shell
curl -i http://localhost:8888/greet/from/you
```
the response looks like:
```http
HTTP/1.1 200 OK
Date: Sun, 30 Aug 2020 15:32:35 GMT
Content-Length: 0
```
4. Write the business logic code
* the dependencies can be passed into the logic within servicecontext.go, like mysql, reds etc.
* add the logic code in logic package according to .api file
5. Generate code like Java, TypeScript, Dart, JavaScript etc. just from the api file
```shell
goctl api java -api greet.api -dir greet
goctl api dart -api greet.api -dir greet
...
```
## 7. Benchmark
![benchmark](doc/images/benchmark.png)
[Checkout the test code](https://github.com/smallnest/go-web-framework-benchmark)
## 8. Documents (adding)
* [Rapid development of microservice systems](doc/shorturl-en.md)
* [Rapid development of microservice systems - multiple RPCs](doc/bookstore-en.md)

@ -1,4 +1,4 @@
English | [简体中文](readme_zh-CN.md)
[English](readme-en.md) | 简体中文
# go-zero
@ -8,82 +8,82 @@ English | [简体中文](readme_zh-CN.md)
[![Release](https://img.shields.io/github/v/release/tal-tech/go-zero.svg?style=flat-square)](https://github.com/tal-tech/go-zero)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
## 0. what is go-zero?
## 0. go-zero介绍
go-zero is a web and rpc framework that with lots of engineering practices builtin. Its born to ensure the stability of the busy services with resilience design, and has been serving sites with tens of millions users for years.
go-zero是一个集成了各种工程实践的web和rpc框架。通过弹性设计保障了大并发服务端的稳定性经受了充分的实战检验。
go-zero contains simple API description syntax and code generation tool called `goctl`. You can generate Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript from .api files with `goctl`.
go-zero 包含极简的 API 定义和生成工具 goctl可以根据定义的 api 文件一键生成 Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript 代码,并可直接运行。
Advantages of go-zero:
使用go-zero的好处
* improve the stability of the services with tens of millions of daily active users
* builtin chained timeout control, concurrency control, rate limit, adaptive circuit breaker, adaptive load shedding, even no configuration needed
* builtin middlewares also can be integrated into your frameworks
* simple API syntax, one command to generate couple different languages
* auto validate the request parameters from clients
* plenty of builtin microservice management and concurrent toolkits
* 轻松获得支撑千万日活服务的稳定性
* 内建级联超时控制、限流、自适应熔断、自适应降载等微服务治理能力,无需配置和额外代码
* 微服务治理中间件可无缝集成到其它现有框架使用
* 极简的API描述一键生成各端代码
* 自动校验客户端请求参数合法性
* 大量微服务治理和并发工具包
<img src="doc/images/architecture-en.png" alt="Architecture" width="1500" />
<img src="doc/images/architecture.png" alt="架构图" width="1500" />
## 1. Backgrounds of go-zero
## 1. go-zero框架背景
At the beginning of 2018, we heavily suffered from frequent downtime. We decided to re-design our system, from monolithic architecture with Java+MongoDB to microservice architecture. After researches and comparison, we chose to:
18年初晓黑板后端在经过频繁的宕机后决定从`Java+MongoDB`的单体架构迁移到微服务架构,经过仔细思考和对比,我们决定:
* Golang based
* great performance
* simple syntax
* proven engineering efficiency
* extreme deployment experience
* less server resource consumption
* Self-designed microservice architecture
* I have rich experience on designing microservice architectures
* easy to location the problems
* easy to extend the features
* 基于Go语言
* 高效的性能
* 简洁的语法
* 广泛验证的工程效率
* 极致的部署体验
* 极低的服务端资源成本
* 自研微服务框架
* 个人有过很多微服务框架自研经验
* 需要有更快速的问题定位能力
* 更便捷的增加新特性
## 2. Design considerations on go-zero
## 2. go-zero框架设计思考
By designing the microservice architecture, we expected to ensure the stability, as well as the productivity. And from just the beginning, we have the following design principles:
对于微服务框架的设计,我们期望保障微服务稳定性的同时,也要特别注重研发效率。所以设计之初,我们就有如下一些准则:
* keep it simple
* high availability
* stable on high concurrency
* easy to extend
* resilience design, failure-oriented programming
* try best to be friendly to the business logic development, encapsulate the complexity
* one thing, one way
* 保持简单
* 高可用
* 高并发
* 易扩展
* 弹性设计,面向故障编程
* 尽可能对业务开发友好,封装复杂度
* 尽可能约束做一件事只有一种方式
After almost half a year, we finished the transfer from monolithic system to microservice system, and deployed on August 2018. The new system guaranteed the business growth, and the system stability.
我们经历不到半年时间,彻底完成了从`Java+MongoDB`到`Golang+MySQL`为主的微服务体系迁移并于18年8月底完全上线稳定保障了晓黑板后续增长确保了整个服务的高可用。
## 3. The implementation and features of go-zero
## 3. go-zero项目实现和特点
go-zero is a web and rpc framework that integrates lots of engineering practices. The features are mainly listed below:
go-zero是一个集成了各种工程实践的包含web和rpc框架有如下主要特点
* powerful tool included, less code to write
* simple interfaces
* fully compatible with net/http
* middlewares are supported, easy to extend
* high performance
* failure-oriented programming, resilience design
* builtin service discovery, load balancing
* builtin concurrency control, adaptive circuit breaker, adaptive load shedding, auto trigger, auto recover
* auto validation of API request parameters
* chained timeout control
* auto management of data caching
* call tracing, metrics and monitoring
* high concurrency protected
* 强大的工具支持,尽可能少的代码编写
* 极简的接口
* 完全兼容net/http
* 支持中间件,方便扩展
* 高性能
* 面向故障编程,弹性设计
* 内建服务发现、负载均衡
* 内建限流、熔断、降载,且自动触发,自动恢复
* API参数自动校验
* 超时级联控制
* 自动缓存控制
* 链路跟踪、统计报警等
* 高并发支撑,稳定保障了晓黑板疫情期间每天的流量洪峰
As below, go-zero protects the system with couple layers and mechanisms:
如下图,我们从多个层面保障了整体服务的高可用:
![Resilience](doc/images/resilience-en.png)
![弹性设计](doc/images/resilience.jpg)
## 4. Future development plans of go-zero
## 4. go-zero近期开发计划
* auto generate API mock server, make the client debugging eaisier
* auto generate the simple integration test for the server side just from the .api files
* 自动生成API mock server便于客户端开发
* 自动生成服务端功能测试
## 5. Installation
Run the following command under your project:
在项目目录下通过如下命令安装:
```shell
go get -u github.com/tal-tech/go-zero
@ -91,27 +91,27 @@ go get -u github.com/tal-tech/go-zero
## 6. Quick Start
0. full examples can be checked out from below:
0. 完整示例请查看
[Rapid development of microservice systems](doc/shorturl-en.md)
[快速构建高并发微服务](doc/shorturl.md)
[Rapid development of microservice systems - multiple RPCs](doc/bookstore-en.md)
[快速构建高并发微服务-多RPC版](doc/bookstore.md)
1. install goctl
1. 安装goctl工具
`goctl`can be read as `go control`. `goctl means not to be controlled by code, instead, we control it. The inside `go` is not `golang`. At the very beginning, I was expecting it to help us improve the productivity, and make our lives easier.
`goctl`读作`go control`,不要读成`go C-T-L`。`goctl`的意思是不要被代码控制,而是要去控制它。其中的`go`不是指`golang`。在设计`goctl`之初,我就希望通过`她`来解放我们的双手👈
```shell
GO111MODULE=on go get -u github.com/tal-tech/go-zero/tools/goctl
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/go-zero/tools/goctl
```
make sure goctl is executable.
确保goctl可执行
2. create the API file, like greet.api, you can install the plugin of goctl in vs code, api syntax is supported.
2. 定义API文件比如greet.api可以在vs code里安装`goctl`插件支持api语法
```go
type Request struct {
Name string `path:"name,options=you|me"` // parameters are auto validated
Name string `path:"name,options=you|me"` // 框架自动验证请求参数是否合法
}
type Response struct {
@ -126,55 +126,53 @@ go get -u github.com/tal-tech/go-zero
}
```
the .api files also can be generate by goctl, like below:
也可以通过goctl生成api模本文件命令如下
```shell
goctl api -o greet.api
```
3. generate the go server side code
3. 生成go服务端代码
```shell
goctl api go -api greet.api -dir greet
```
the generated files look like:
生成的文件结构如下:
```
├── greet
│   ├── etc
│   │   └── greet-api.yaml // configuration file
│   ├── greet.go // main file
│   │   └── greet-api.yaml // 配置文件
│   ├── greet.go // main文件
│   └── internal
│   ├── config
│   │   └── config.go // configuration definition
│   │   └── config.go // 配置定义
│   ├── handler
│   │   ├── greethandler.go // get/put/post/delete routes are defined here
│   │   └── routes.go // routes list
│   │   ├── greethandler.go // get/put/post/delete等路由定义文件
│   │   └── routes.go // 路由列表
│   ├── logic
│   │   └── greetlogic.go // request logic can be written here
│   │   └── greetlogic.go // 请求逻辑处理文件
│   ├── svc
│   │   └── servicecontext.go // service context, mysql/redis can be passed in here
│   │   └── servicecontext.go // 请求上下文可以传入mysql, redis等依赖
│   └── types
│   └── types.go // request/response defined here
└── greet.api // api description file
│   └── types.go // 请求、返回等类型定义
└── greet.api // api描述文件
```
the generated code can be run directly:
生成的代码可以直接运行:
```shell
cd greet
go run greet.go -f etc/greet-api.yaml
```
by default, its listening on port 8888, while it can be changed in configuration file.
you can check it by curl:
默认侦听在8888端口可以在配置文件里修改可以通过curl请求
```shell
curl -i http://localhost:8888/greet/from/you
```
the response looks like:
返回如下:
```http
HTTP/1.1 200 OK
@ -182,11 +180,12 @@ go get -u github.com/tal-tech/go-zero
Content-Length: 0
```
4. Write the business logic code
编写业务代码:
* 可以在servicecontext.go里面传递依赖给logic比如mysql, redis等
* 在api定义的get/post/put/delete等请求对应的logic里增加业务处理逻辑
* the dependencies can be passed into the logic within servicecontext.go, like mysql, reds etc.
* add the logic code in logic package according to .api file
5. Generate code like Java, TypeScript, Dart, JavaScript etc. just from the api file
4. 可以根据api文件生成前端需要的Java, TypeScript, Dart, JavaScript代码
```shell
goctl api java -api greet.api -dir greet
@ -198,9 +197,16 @@ go get -u github.com/tal-tech/go-zero
![benchmark](doc/images/benchmark.png)
[Checkout the test code](https://github.com/smallnest/go-web-framework-benchmark)
[测试代码见这里](https://github.com/smallnest/go-web-framework-benchmark)
## 8. 文档 (逐步完善中)
* [快速构建高并发微服务](doc/shorturl.md)
* [快速构建高并发微服务-多RPC版](doc/bookstore.md)
* [goctl使用帮助](doc/goctl.md)
* [通过MapReduce降低服务响应时间](doc/mapreduce.md)
* [关键字替换和敏感词过滤工具](doc/keywords.md)
## 8. Documents (adding)
## 9. 微信交流群
* [Rapid development of microservice systems](doc/shorturl-en.md)
* [Rapid development of microservice systems - multiple RPCs](doc/bookstore-en.md)
<img src="doc/images/wechat.jpg" alt="wechat" width="300" />

@ -1,212 +0,0 @@
[English](readme.md) | 简体中文
# go-zero
[![Go](https://github.com/tal-tech/go-zero/workflows/Go/badge.svg?branch=master)](https://github.com/tal-tech/go-zero/actions)
[![codecov](https://codecov.io/gh/tal-tech/go-zero/branch/master/graph/badge.svg)](https://codecov.io/gh/tal-tech/go-zero)
[![Go Report Card](https://goreportcard.com/badge/github.com/tal-tech/go-zero)](https://goreportcard.com/report/github.com/tal-tech/go-zero)
[![Release](https://img.shields.io/github/v/release/tal-tech/go-zero.svg?style=flat-square)](https://github.com/tal-tech/go-zero)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
## 0. go-zero介绍
go-zero是一个集成了各种工程实践的web和rpc框架。通过弹性设计保障了大并发服务端的稳定性经受了充分的实战检验。
go-zero 包含极简的 API 定义和生成工具 goctl可以根据定义的 api 文件一键生成 Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript 代码,并可直接运行。
使用go-zero的好处
* 轻松获得支撑千万日活服务的稳定性
* 内建级联超时控制、限流、自适应熔断、自适应降载等微服务治理能力,无需配置和额外代码
* 微服务治理中间件可无缝集成到其它现有框架使用
* 极简的API描述一键生成各端代码
* 自动校验客户端请求参数合法性
* 大量微服务治理和并发工具包
<img src="doc/images/architecture.png" alt="架构图" width="1500" />
## 1. go-zero框架背景
18年初晓黑板后端在经过频繁的宕机后决定从`Java+MongoDB`的单体架构迁移到微服务架构,经过仔细思考和对比,我们决定:
* 基于Go语言
* 高效的性能
* 简洁的语法
* 广泛验证的工程效率
* 极致的部署体验
* 极低的服务端资源成本
* 自研微服务框架
* 个人有过很多微服务框架自研经验
* 需要有更快速的问题定位能力
* 更便捷的增加新特性
## 2. go-zero框架设计思考
对于微服务框架的设计,我们期望保障微服务稳定性的同时,也要特别注重研发效率。所以设计之初,我们就有如下一些准则:
* 保持简单
* 高可用
* 高并发
* 易扩展
* 弹性设计,面向故障编程
* 尽可能对业务开发友好,封装复杂度
* 尽可能约束做一件事只有一种方式
我们经历不到半年时间,彻底完成了从`Java+MongoDB`到`Golang+MySQL`为主的微服务体系迁移并于18年8月底完全上线稳定保障了晓黑板后续增长确保了整个服务的高可用。
## 3. go-zero项目实现和特点
go-zero是一个集成了各种工程实践的包含web和rpc框架有如下主要特点
* 强大的工具支持,尽可能少的代码编写
* 极简的接口
* 完全兼容net/http
* 支持中间件,方便扩展
* 高性能
* 面向故障编程,弹性设计
* 内建服务发现、负载均衡
* 内建限流、熔断、降载,且自动触发,自动恢复
* API参数自动校验
* 超时级联控制
* 自动缓存控制
* 链路跟踪、统计报警等
* 高并发支撑,稳定保障了晓黑板疫情期间每天的流量洪峰
如下图,我们从多个层面保障了整体服务的高可用:
![弹性设计](doc/images/resilience.jpg)
## 4. go-zero近期开发计划
* 自动生成API mock server便于客户端开发
* 自动生成服务端功能测试
## 5. Installation
在项目目录下通过如下命令安装:
```shell
go get -u github.com/tal-tech/go-zero
```
## 6. Quick Start
0. 完整示例请查看
[快速构建高并发微服务](doc/shorturl.md)
[快速构建高并发微服务-多RPC版](doc/bookstore.md)
1. 安装goctl工具
`goctl`读作`go control`,不要读成`go C-T-L`。`goctl`的意思是不要被代码控制,而是要去控制它。其中的`go`不是指`golang`。在设计`goctl`之初,我就希望通过`她`来解放我们的双手👈
```shell
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/go-zero/tools/goctl
```
确保goctl可执行
2. 定义API文件比如greet.api可以在vs code里安装`goctl`插件支持api语法
```go
type Request struct {
Name string `path:"name,options=you|me"` // 框架自动验证请求参数是否合法
}
type Response struct {
Message string `json:"message"`
}
service greet-api {
@server(
handler: GreetHandler
)
get /greet/from/:name(Request) returns (Response);
}
```
也可以通过goctl生成api模本文件命令如下
```shell
goctl api -o greet.api
```
3. 生成go服务端代码
```shell
goctl api go -api greet.api -dir greet
```
生成的文件结构如下:
```
├── greet
│   ├── etc
│   │   └── greet-api.yaml // 配置文件
│   ├── greet.go // main文件
│   └── internal
│   ├── config
│   │   └── config.go // 配置定义
│   ├── handler
│   │   ├── greethandler.go // get/put/post/delete等路由定义文件
│   │   └── routes.go // 路由列表
│   ├── logic
│   │   └── greetlogic.go // 请求逻辑处理文件
│   ├── svc
│   │   └── servicecontext.go // 请求上下文可以传入mysql, redis等依赖
│   └── types
│   └── types.go // 请求、返回等类型定义
└── greet.api // api描述文件
```
生成的代码可以直接运行:
```shell
cd greet
go run greet.go -f etc/greet-api.yaml
```
默认侦听在8888端口可以在配置文件里修改可以通过curl请求
```shell
curl -i http://localhost:8888/greet/from/you
```
返回如下:
```http
HTTP/1.1 200 OK
Date: Sun, 30 Aug 2020 15:32:35 GMT
Content-Length: 0
```
编写业务代码:
* 可以在servicecontext.go里面传递依赖给logic比如mysql, redis等
* 在api定义的get/post/put/delete等请求对应的logic里增加业务处理逻辑
4. 可以根据api文件生成前端需要的Java, TypeScript, Dart, JavaScript代码
```shell
goctl api java -api greet.api -dir greet
goctl api dart -api greet.api -dir greet
...
```
## 7. Benchmark
![benchmark](doc/images/benchmark.png)
[测试代码见这里](https://github.com/smallnest/go-web-framework-benchmark)
## 8. 文档 (逐步完善中)
* [快速构建高并发微服务](doc/shorturl.md)
* [快速构建高并发微服务-多RPC版](doc/bookstore.md)
* [goctl使用帮助](doc/goctl.md)
* [通过MapReduce降低服务响应时间](doc/mapreduce.md)
* [关键字替换和敏感词过滤工具](doc/keywords.md)
## 9. 微信交流群
<img src="doc/images/wechat.jpg" alt="wechat" width="300" />
Loading…
Cancel
Save