go-zero is a web and rpc framework that with lots of engineering practices builtin. It’s born to ensure the stabibility of the busy services with resilience design, and has been serving sites with tens of millions users for years.
go-zero 包含极简的 API 定义和生成工具 goctl,可以根据定义的 api 文件一键生成 Go, iOS, Android, Kotlin, Dart, TypeScript, JavaScript 代码,并可直接运行。
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的好处:
Advantages of go-zero:
* 轻松获得支撑千万日活服务的稳定性
* 内建级联超时控制、限流、自适应熔断、自适应降载等微服务治理能力,无需配置和额外代码
* 微服务治理中间件可无缝集成到其它现有框架使用
* 极简的API描述,一键生成各端代码
* 自动校验客户端请求参数合法性
* 大量微服务治理和并发工具包
* 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
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:
* 基于Go语言
* 高效的性能
* 简洁的语法
* 广泛验证的工程效率
* 极致的部署体验
* 极低的服务端资源成本
* 自研微服务框架
* 个人有过很多微服务框架自研经验
* 需要有更快速的问题定位能力
* 更便捷的增加新特性
* 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
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
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. go-zero项目实现和特点
## 3. The implementation and features of go-zero
go-zero是一个集成了各种工程实践的包含web和rpc框架,有如下主要特点:
go-zero is a web and rpc framework that integrates lots of engineering practices. The features are mainly listed below:
* 强大的工具支持,尽可能少的代码编写
* 极简的接口
* 完全兼容net/http
* 支持中间件,方便扩展
* 高性能
* 面向故障编程,弹性设计
* 内建服务发现、负载均衡
* 内建限流、熔断、降载,且自动触发,自动恢复
* API参数自动校验
* 超时级联控制
* 自动缓存控制
* 链路跟踪、统计报警等
* 高并发支撑,稳定保障了晓黑板疫情期间每天的流量洪峰
* 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:
![弹性设计](doc/images/resilience.jpg)
![Resilience](doc/images/resilience-en.png)
## 4. go-zero近期开发计划
## 4. Future development plans of go-zero
* 自动生成API mock server,便于客户端开发
* 自动生成服务端功能测试
* 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
@ -89,27 +91,27 @@ go get -u github.com/tal-tech/go-zero
## 6. Quick Start
0. 完整示例请查看
0. full examples can be checked out from below:
[快速构建高并发微服务](doc/shorturl.md)
[Rapid development of microservice systems](doc/shorturl.md)
[快速构建高并发微服务-多RPC版](doc/bookstore.md)
[Rapid development of microservice systems - multiple RPCs](doc/bookstore.md)
`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 GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/go-zero/tools/goctl
GO111MODULE=on go get -u github.com/tal-tech/go-zero/tools/goctl