From 153e47565d44b7564959983e225b8ee937009bd1 Mon Sep 17 00:00:00 2001 From: Windfarer Date: Wed, 16 Sep 2020 11:49:59 +0800 Subject: [PATCH] init --- README.md | 10 +-- .../database-tidb.md => docs/.nojekyll | 0 {doc/wiki-cn => docs}/FAQ.md | 0 {doc/wiki-cn => docs}/README.md | 75 ++++++++---------- doc/wiki-cn/summary.md => docs/_sidebar.md | 3 +- {doc/wiki-cn => docs}/blademaster-mid.md | 5 +- {doc/wiki-cn => docs}/blademaster-mod.md | 5 +- {doc/wiki-cn => docs}/blademaster-pb.md | 3 - .../blademaster-quickstart.md | 3 - {doc/wiki-cn => docs}/blademaster.md | 7 +- {doc/wiki-cn => docs}/breaker.md | 0 {doc/wiki-cn => docs}/cache-mc.md | 3 - {doc/wiki-cn => docs}/cache-redis.md | 3 - {doc/wiki-cn => docs}/cache.md | 3 - {doc/wiki-cn => docs}/config-paladin.md | 0 {doc/wiki-cn => docs}/config.md | 3 - {doc/wiki-cn => docs}/database-hbase.md | 3 - {doc/wiki-cn => docs}/database-mysql-orm.md | 3 - {doc/wiki-cn => docs}/database-mysql.md | 3 - .../log-agent.md => docs/database-tidb.md | 0 {doc/wiki-cn => docs}/database.md | 3 - {doc/wiki-cn => docs}/ecode.md | 0 {doc => docs}/img/bm-arch-2-2.png | Bin {doc => docs}/img/bm-arch-2-3.png | Bin {doc => docs}/img/bm-handlers.png | Bin {doc => docs}/img/kratos-log.jpg | Bin {doc => docs}/img/kratos.png | Bin {doc => docs}/img/kratos2.png | Bin {doc => docs}/img/kratos3.png | Bin .../img/ratelimit-benchmark-up-1.png | Bin .../img/ratelimit-rolling-window.png | Bin {doc => docs}/img/zipkin.jpg | Bin docs/index.html | 22 +++++ {doc/wiki-cn => docs}/install.md | 3 - {doc/wiki-cn => docs}/kratos-genbts.md | 3 - {doc/wiki-cn => docs}/kratos-genmc.md | 3 - {doc/wiki-cn => docs}/kratos-protoc.md | 3 - {doc/wiki-cn => docs}/kratos-swagger.md | 3 - {doc/wiki-cn => docs}/kratos-tool.md | 5 -- docs/log-agent.md | 0 {doc/wiki-cn => docs}/logger.md | 3 - {doc/wiki-cn => docs}/protoc.md | 3 - {doc/wiki-cn => docs}/quickstart.md | 3 - {doc/wiki-cn => docs}/ratelimit.md | 7 +- {doc/wiki-cn => docs}/trace.md | 2 +- {doc/wiki-cn => docs}/ut-support.md | 25 +++--- {doc/wiki-cn => docs}/ut-testcli.md | 0 {doc/wiki-cn => docs}/ut-testgen.md | 7 -- {doc/wiki-cn => docs}/ut.md | 6 -- {doc/wiki-cn => docs}/warden-balancer.md | 4 - {doc/wiki-cn => docs}/warden-mid.md | 7 +- {doc/wiki-cn => docs}/warden-pb.md | 3 - {doc/wiki-cn => docs}/warden-quickstart.md | 4 - {doc/wiki-cn => docs}/warden-resolver.md | 4 - {doc/wiki-cn => docs}/warden.md | 3 - 55 files changed, 85 insertions(+), 173 deletions(-) rename doc/wiki-cn/database-tidb.md => docs/.nojekyll (100%) rename {doc/wiki-cn => docs}/FAQ.md (100%) rename {doc/wiki-cn => docs}/README.md (96%) rename doc/wiki-cn/summary.md => docs/_sidebar.md (95%) rename {doc/wiki-cn => docs}/blademaster-mid.md (98%) rename {doc/wiki-cn => docs}/blademaster-mod.md (97%) rename {doc/wiki-cn => docs}/blademaster-pb.md (98%) rename {doc/wiki-cn => docs}/blademaster-quickstart.md (99%) rename {doc/wiki-cn => docs}/blademaster.md (96%) rename {doc/wiki-cn => docs}/breaker.md (100%) rename {doc/wiki-cn => docs}/cache-mc.md (99%) rename {doc/wiki-cn => docs}/cache-redis.md (99%) rename {doc/wiki-cn => docs}/cache.md (91%) rename {doc/wiki-cn => docs}/config-paladin.md (100%) rename {doc/wiki-cn => docs}/config.md (98%) rename {doc/wiki-cn => docs}/database-hbase.md (95%) rename {doc/wiki-cn => docs}/database-mysql-orm.md (98%) rename {doc/wiki-cn => docs}/database-mysql.md (99%) rename doc/wiki-cn/log-agent.md => docs/database-tidb.md (100%) rename {doc/wiki-cn => docs}/database.md (93%) rename {doc/wiki-cn => docs}/ecode.md (100%) rename {doc => docs}/img/bm-arch-2-2.png (100%) rename {doc => docs}/img/bm-arch-2-3.png (100%) rename {doc => docs}/img/bm-handlers.png (100%) rename {doc => docs}/img/kratos-log.jpg (100%) rename {doc => docs}/img/kratos.png (100%) rename {doc => docs}/img/kratos2.png (100%) rename {doc => docs}/img/kratos3.png (100%) rename {doc => docs}/img/ratelimit-benchmark-up-1.png (100%) rename {doc => docs}/img/ratelimit-rolling-window.png (100%) rename {doc => docs}/img/zipkin.jpg (100%) create mode 100644 docs/index.html rename {doc/wiki-cn => docs}/install.md (96%) rename {doc/wiki-cn => docs}/kratos-genbts.md (95%) rename {doc/wiki-cn => docs}/kratos-genmc.md (98%) rename {doc/wiki-cn => docs}/kratos-protoc.md (96%) rename {doc/wiki-cn => docs}/kratos-swagger.md (85%) rename {doc/wiki-cn => docs}/kratos-tool.md (96%) create mode 100644 docs/log-agent.md rename {doc/wiki-cn => docs}/logger.md (94%) rename {doc/wiki-cn => docs}/protoc.md (97%) rename {doc/wiki-cn => docs}/quickstart.md (98%) rename {doc/wiki-cn => docs}/ratelimit.md (93%) rename {doc/wiki-cn => docs}/trace.md (98%) rename {doc/wiki-cn => docs}/ut-support.md (98%) rename {doc/wiki-cn => docs}/ut-testcli.md (100%) rename {doc/wiki-cn => docs}/ut-testgen.md (92%) rename {doc/wiki-cn => docs}/ut.md (87%) rename {doc/wiki-cn => docs}/warden-balancer.md (95%) rename {doc/wiki-cn => docs}/warden-mid.md (99%) rename {doc/wiki-cn => docs}/warden-pb.md (97%) rename {doc/wiki-cn => docs}/warden-quickstart.md (99%) rename {doc/wiki-cn => docs}/warden-resolver.md (99%) rename {doc/wiki-cn => docs}/warden.md (96%) diff --git a/README.md b/README.md index 73184b86a..51559e2bd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![kratos](doc/img/kratos3.png) +![kratos](docs/img/kratos3.png) [![Language](https://img.shields.io/badge/Language-Go-blue.svg)](https://golang.org/) [![Build Status](https://github.com/go-kratos/kratos/workflows/Go/badge.svg)](https://github.com/go-kratos/kratos/actions) @@ -20,7 +20,7 @@ Kratos是[bilibili](https://www.bilibili.com)开源的一套Go微服务框架, * GRPC Warden:基于官方gRPC开发,集成[discovery](https://github.com/bilibili/discovery)服务发现,并融合P2C负载均衡; * Cache:优雅的接口化设计,非常方便的缓存序列化,推荐结合代理模式[overlord](https://github.com/bilibili/overlord); * Database:集成MySQL/HBase/TiDB,添加熔断保护和统计支持,可快速发现数据层压力; -* Config:方便易用的[paladin sdk](doc/wiki-cn/config.md),可配合远程配置中心,实现配置版本管理和更新; +* Config:方便易用的[paladin sdk](https://windfarer.github.io/kratos/#/config),可配合远程配置中心,实现配置版本管理和更新; * Log:类似[zap](https://github.com/uber-go/zap)的field实现高性能日志库,并结合log-agent实现远程日志管理; * Trace:基于opentracing,集成了全链路trace支持(gRPC/HTTP/MySQL/Redis/Memcached); * Kratos Tool:工具链,可快速生成标准项目,或者通过Protobuf生成代码,非常便捷使用gRPC、HTTP、swagger文档; @@ -50,12 +50,12 @@ go build 打开浏览器访问:[http://localhost:8000/kratos-demo/start](http://localhost:8000/kratos-demo/start),你会看到输出了`Golang 大法好 !!!` -[快速开始](doc/wiki-cn/quickstart.md) [kratos工具](doc/wiki-cn/kratos-tool.md) +[快速开始](https://windfarer.github.io/kratos/#/quickstart) [kratos工具](https://windfarer.github.io/kratos/#/kratos-tool) ## Documentation -> [简体中文](doc/wiki-cn/summary.md) -> [FAQ](doc/wiki-cn/FAQ.md) +> [简体中文](https://windfarer.github.io/kratos) +> [FAQ](https://windfarer.github.io/kratos/#/FAQ) ## License Kratos is under the MIT license. See the [LICENSE](./LICENSE) file for details. diff --git a/doc/wiki-cn/database-tidb.md b/docs/.nojekyll similarity index 100% rename from doc/wiki-cn/database-tidb.md rename to docs/.nojekyll diff --git a/doc/wiki-cn/FAQ.md b/docs/FAQ.md similarity index 100% rename from doc/wiki-cn/FAQ.md rename to docs/FAQ.md diff --git a/doc/wiki-cn/README.md b/docs/README.md similarity index 96% rename from doc/wiki-cn/README.md rename to docs/README.md index 45e7e4a4a..53d878239 100644 --- a/doc/wiki-cn/README.md +++ b/docs/README.md @@ -1,40 +1,35 @@ -# Kratos - -Kratos是bilibili开源的一套Go微服务框架,包含大量微服务相关框架及工具。 - -### Goals - -我们致力于提供完整的微服务研发体验,整合相关框架及工具后,微服务治理相关部分可对整体业务开发周期无感,从而更加聚焦于业务交付。对每位开发者而言,整套Kratos框架也是不错的学习仓库,可以了解和参考到bilibili在微服务方面的技术积累和经验。 - -### Principles - -* 简单:不过度设计,代码平实简单 -* 通用:通用业务开发所需要的基础库的功能 -* 高效:提高业务迭代的效率 -* 稳定:基础库可测试性高,覆盖率高,有线上实践安全可靠 -* 健壮:通过良好的基础库设计,减少错用 -* 高性能:性能高,但不特定为了性能做hack优化,引入unsafe -* 扩展性:良好的接口设计,来扩展实现,或者通过新增基础库目录来扩展功能 -* 容错性:为失败设计,大量引入对SRE的理解,鲁棒性高 -* 工具链:包含大量工具链,比如cache代码生成,lint工具等等 - -### Features -* HTTP Blademaster:核心基于[gin](https://github.com/gin-gonic/gin)进行模块化设计,简单易用、核心足够轻量; -* GRPC Warden:基于官方gRPC开发,集成[discovery](https://github.com/bilibili/discovery)服务发现,并融合P2C负载均衡; -* Cache:优雅的接口化设计,非常方便的缓存序列化,推荐结合代理模式[overlord](https://github.com/bilibili/overlord); -* Database:集成MySQL/HBase/TiDB,添加熔断保护和统计支持,可快速发现数据层压力; -* Config:方便易用的[paladin sdk](config-paladin.md),可配合远程配置中心,实现配置版本管理和更新; -* Log:类似[zap](https://github.com/uber-go/zap)的field实现高性能日志库,并结合log-agent实现远程日志管理; -* Trace:基于opentracing,集成了全链路trace支持(gRPC/HTTP/MySQL/Redis/Memcached); -* Kratos Tool:工具链,可快速生成标准项目,或者通过Protobuf生成代码,非常便捷使用gRPC、HTTP、swagger文档; - - -
- -------------- - -> 名字来源于:《战神》游戏以希腊神话为背景,讲述由凡人成为战神的奎托斯(Kratos)成为战神并展开弑神屠杀的冒险历程。 - -------------- - -[文档目录树](summary.md) +# Kratos + +Kratos是bilibili开源的一套Go微服务框架,包含大量微服务相关框架及工具。 + +### Goals + +我们致力于提供完整的微服务研发体验,整合相关框架及工具后,微服务治理相关部分可对整体业务开发周期无感,从而更加聚焦于业务交付。对每位开发者而言,整套Kratos框架也是不错的学习仓库,可以了解和参考到bilibili在微服务方面的技术积累和经验。 + +### Principles + +* 简单:不过度设计,代码平实简单 +* 通用:通用业务开发所需要的基础库的功能 +* 高效:提高业务迭代的效率 +* 稳定:基础库可测试性高,覆盖率高,有线上实践安全可靠 +* 健壮:通过良好的基础库设计,减少错用 +* 高性能:性能高,但不特定为了性能做hack优化,引入unsafe +* 扩展性:良好的接口设计,来扩展实现,或者通过新增基础库目录来扩展功能 +* 容错性:为失败设计,大量引入对SRE的理解,鲁棒性高 +* 工具链:包含大量工具链,比如cache代码生成,lint工具等等 + +### Features +* HTTP Blademaster:核心基于[gin](https://github.com/gin-gonic/gin)进行模块化设计,简单易用、核心足够轻量; +* GRPC Warden:基于官方gRPC开发,集成[discovery](https://github.com/bilibili/discovery)服务发现,并融合P2C负载均衡; +* Cache:优雅的接口化设计,非常方便的缓存序列化,推荐结合代理模式[overlord](https://github.com/bilibili/overlord); +* Database:集成MySQL/HBase/TiDB,添加熔断保护和统计支持,可快速发现数据层压力; +* Config:方便易用的[paladin sdk](config-paladin.md),可配合远程配置中心,实现配置版本管理和更新; +* Log:类似[zap](https://github.com/uber-go/zap)的field实现高性能日志库,并结合log-agent实现远程日志管理; +* Trace:基于opentracing,集成了全链路trace支持(gRPC/HTTP/MySQL/Redis/Memcached); +* Kratos Tool:工具链,可快速生成标准项目,或者通过Protobuf生成代码,非常便捷使用gRPC、HTTP、swagger文档; + + +------------- + +> 名字来源于:《战神》游戏以希腊神话为背景,讲述由凡人成为战神的奎托斯(Kratos)成为战神并展开弑神屠杀的冒险历程。 + diff --git a/doc/wiki-cn/summary.md b/docs/_sidebar.md similarity index 95% rename from doc/wiki-cn/summary.md rename to docs/_sidebar.md index 3986cd8ca..9251dfc62 100644 --- a/doc/wiki-cn/summary.md +++ b/docs/_sidebar.md @@ -1,8 +1,7 @@ -# Summary - * [介绍](README.md) * [快速开始](quickstart.md) * [案例](https://github.com/go-kratos/kratos-demo) +* [FAQ](FAQ.md) * [http blademaster](blademaster.md) * [bm quickstart](blademaster-quickstart.md) * [bm module](blademaster-mod.md) diff --git a/doc/wiki-cn/blademaster-mid.md b/docs/blademaster-mid.md similarity index 98% rename from doc/wiki-cn/blademaster-mid.md rename to docs/blademaster-mid.md index 204b6b878..e379b97dc 100644 --- a/doc/wiki-cn/blademaster-mid.md +++ b/docs/blademaster-mid.md @@ -158,7 +158,7 @@ e.POST("/api", cors, myHandler) ## 自适应限流 -更多关于自适应限流的信息可参考:[kratos 自适应限流](/doc/wiki-cn/ratelimit.md)。如要使用如下: +更多关于自适应限流的信息可参考:[kratos 自适应限流](ratelimit.md)。如要使用如下: ```go e := bm.DefaultServer(nil) @@ -175,6 +175,3 @@ e.GET("/api", csrf, myHandler) [bm模块说明](blademaster-mod.md) [bm基于pb生成](blademaster-pb.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/blademaster-mod.md b/docs/blademaster-mod.md similarity index 97% rename from doc/wiki-cn/blademaster-mod.md rename to docs/blademaster-mod.md index e72f1eb52..e8c81d704 100644 --- a/doc/wiki-cn/blademaster-mod.md +++ b/docs/blademaster-mod.md @@ -72,7 +72,7 @@ func (c *Context) Protobuf(data proto.Message, err error) # Handler -![handler](/doc/img/bm-handlers.png) +![handler](img/bm-handlers.png) 初次接触`blademaster`的用户可能会对其`Handler`的流程处理产生不小的疑惑,实际上`bm`对`Handler`对处理非常简单: @@ -86,6 +86,3 @@ func (c *Context) Protobuf(data proto.Message, err error) [bm中间件](blademaster-mid.md) [bm基于pb生成](blademaster-pb.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/blademaster-pb.md b/docs/blademaster-pb.md similarity index 98% rename from doc/wiki-cn/blademaster-pb.md rename to docs/blademaster-pb.md index bf368b848..0b693af13 100644 --- a/doc/wiki-cn/blademaster-pb.md +++ b/docs/blademaster-pb.md @@ -81,6 +81,3 @@ kratos tool swagger serve api/api.swagger.json [bm模块说明](blademaster-mod.md) [bm中间件](blademaster-mid.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/blademaster-quickstart.md b/docs/blademaster-quickstart.md similarity index 99% rename from doc/wiki-cn/blademaster-quickstart.md rename to docs/blademaster-quickstart.md index 7e842f96f..84d84a214 100644 --- a/doc/wiki-cn/blademaster-quickstart.md +++ b/docs/blademaster-quickstart.md @@ -190,6 +190,3 @@ go tool pprof http://127.0.0.1:8000/debug/pprof/profile [bm中间件](blademaster-mid.md) [bm基于pb生成](blademaster-pb.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/blademaster.md b/docs/blademaster.md similarity index 96% rename from doc/wiki-cn/blademaster.md rename to docs/blademaster.md index c656045e1..1915c3ed6 100644 --- a/doc/wiki-cn/blademaster.md +++ b/docs/blademaster.md @@ -21,12 +21,12 @@ # blademaster架构 -![bm-arch](/doc/img/bm-arch-2-2.png) +![bm-arch](img/bm-arch-2-2.png) `blademaster`由几个非常精简的内部模块组成。其中`Router`用于根据请求的路径分发请求,`Context`包含了一个完整的请求信息,`Handler`则负责处理传入的`Context`,`Handlers`为一个列表,一个串一个地执行。 所有的`middlerware`均以`Handler`的形式存在,这样可以保证`blademaster`自身足够精简且扩展性足够强。 -![bm-arch](/doc/img/bm-arch-2-3.png) +![bm-arch](img/bm-arch-2-3.png) `blademaster`处理请求的模式非常简单,大部分的逻辑都被封装在了各种`Handler`中。一般而言,业务逻辑作为最后一个`Handler`。 @@ -41,6 +41,3 @@ [bm中间件](blademaster-mid.md) [bm基于pb生成](blademaster-pb.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/breaker.md b/docs/breaker.md similarity index 100% rename from doc/wiki-cn/breaker.md rename to docs/breaker.md diff --git a/doc/wiki-cn/cache-mc.md b/docs/cache-mc.md similarity index 99% rename from doc/wiki-cn/cache-mc.md rename to docs/cache-mc.md index 0ef73af24..20e1e5fd5 100644 --- a/doc/wiki-cn/cache-mc.md +++ b/docs/cache-mc.md @@ -243,6 +243,3 @@ func (d *Dao) DelCacheDemo(c context.Context, id int64) (err error) { [memcache代码生成器](kratos-genmc.md) [redis模块说明](cache-redis.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/cache-redis.md b/docs/cache-redis.md similarity index 99% rename from doc/wiki-cn/cache-redis.md rename to docs/cache-redis.md index 34ce96856..e1cf3b081 100644 --- a/doc/wiki-cn/cache-redis.md +++ b/docs/cache-redis.md @@ -229,6 +229,3 @@ func (d *Dao) HGETALLDemo(c context.Context, pid int64) (res map[string]int64, e [memcache模块说明](cache-mc.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/cache.md b/docs/cache.md similarity index 91% rename from doc/wiki-cn/cache.md rename to docs/cache.md index 41f87d184..a1e484035 100644 --- a/doc/wiki-cn/cache.md +++ b/docs/cache.md @@ -18,6 +18,3 @@ [redis模块说明](cache-redis.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/config-paladin.md b/docs/config-paladin.md similarity index 100% rename from doc/wiki-cn/config-paladin.md rename to docs/config-paladin.md diff --git a/doc/wiki-cn/config.md b/docs/config.md similarity index 98% rename from doc/wiki-cn/config.md rename to docs/config.md index b218b87b6..f27244ab9 100644 --- a/doc/wiki-cn/config.md +++ b/docs/config.md @@ -46,6 +46,3 @@ Redis、MySQL等业务组件,可以使用静态的配置文件来初始化, [paladin配置sdk](config-paladin.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/database-hbase.md b/docs/database-hbase.md similarity index 95% rename from doc/wiki-cn/database-hbase.md rename to docs/database-hbase.md index 854542b24..327092b7f 100644 --- a/doc/wiki-cn/database-hbase.md +++ b/docs/database-hbase.md @@ -49,6 +49,3 @@ func main() { } ``` -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/database-mysql-orm.md b/docs/database-mysql-orm.md similarity index 98% rename from doc/wiki-cn/database-mysql-orm.md rename to docs/database-mysql-orm.md index 1e16fc771..69b76e089 100644 --- a/doc/wiki-cn/database-mysql-orm.md +++ b/docs/database-mysql-orm.md @@ -90,6 +90,3 @@ checkErr(paladin.Get("db.toml").UnmarshalTOML(&dc)) [tidb模块说明](database-tidb.md) [hbase模块说明](database-hbase.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/database-mysql.md b/docs/database-mysql.md similarity index 99% rename from doc/wiki-cn/database-mysql.md rename to docs/database-mysql.md index 2eab493bb..e189c570f 100644 --- a/doc/wiki-cn/database-mysql.md +++ b/docs/database-mysql.md @@ -243,6 +243,3 @@ if err = tx.Rollback().Error; err!=nil{ [tidb模块说明](database-tidb.md) [hbase模块说明](database-hbase.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/log-agent.md b/docs/database-tidb.md similarity index 100% rename from doc/wiki-cn/log-agent.md rename to docs/database-tidb.md diff --git a/doc/wiki-cn/database.md b/docs/database.md similarity index 93% rename from doc/wiki-cn/database.md rename to docs/database.md index 61d9f81d6..f8cb3ebf2 100644 --- a/doc/wiki-cn/database.md +++ b/docs/database.md @@ -17,6 +17,3 @@ HBase客户端,支持trace、slowlog和统计功能。 TiDB客户端,支持服务发现和熔断功能。 [tidb client](database-tidb.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/ecode.md b/docs/ecode.md similarity index 100% rename from doc/wiki-cn/ecode.md rename to docs/ecode.md diff --git a/doc/img/bm-arch-2-2.png b/docs/img/bm-arch-2-2.png similarity index 100% rename from doc/img/bm-arch-2-2.png rename to docs/img/bm-arch-2-2.png diff --git a/doc/img/bm-arch-2-3.png b/docs/img/bm-arch-2-3.png similarity index 100% rename from doc/img/bm-arch-2-3.png rename to docs/img/bm-arch-2-3.png diff --git a/doc/img/bm-handlers.png b/docs/img/bm-handlers.png similarity index 100% rename from doc/img/bm-handlers.png rename to docs/img/bm-handlers.png diff --git a/doc/img/kratos-log.jpg b/docs/img/kratos-log.jpg similarity index 100% rename from doc/img/kratos-log.jpg rename to docs/img/kratos-log.jpg diff --git a/doc/img/kratos.png b/docs/img/kratos.png similarity index 100% rename from doc/img/kratos.png rename to docs/img/kratos.png diff --git a/doc/img/kratos2.png b/docs/img/kratos2.png similarity index 100% rename from doc/img/kratos2.png rename to docs/img/kratos2.png diff --git a/doc/img/kratos3.png b/docs/img/kratos3.png similarity index 100% rename from doc/img/kratos3.png rename to docs/img/kratos3.png diff --git a/doc/img/ratelimit-benchmark-up-1.png b/docs/img/ratelimit-benchmark-up-1.png similarity index 100% rename from doc/img/ratelimit-benchmark-up-1.png rename to docs/img/ratelimit-benchmark-up-1.png diff --git a/doc/img/ratelimit-rolling-window.png b/docs/img/ratelimit-rolling-window.png similarity index 100% rename from doc/img/ratelimit-rolling-window.png rename to docs/img/ratelimit-rolling-window.png diff --git a/doc/img/zipkin.jpg b/docs/img/zipkin.jpg similarity index 100% rename from doc/img/zipkin.jpg rename to docs/img/zipkin.jpg diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 000000000..b757f801a --- /dev/null +++ b/docs/index.html @@ -0,0 +1,22 @@ + + + + + Document + + + + + + +
+ + + + diff --git a/doc/wiki-cn/install.md b/docs/install.md similarity index 96% rename from doc/wiki-cn/install.md rename to docs/install.md index 9c9e8f873..4ff3e2057 100644 --- a/doc/wiki-cn/install.md +++ b/docs/install.md @@ -64,6 +64,3 @@ go build [kratos工具](kratos-tool.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/kratos-genbts.md b/docs/kratos-genbts.md similarity index 95% rename from doc/wiki-cn/kratos-genbts.md rename to docs/kratos-genbts.md index 7c889ddc4..ca3e74430 100644 --- a/doc/wiki-cn/kratos-genbts.md +++ b/docs/kratos-genbts.md @@ -25,6 +25,3 @@ type _bts interface { 也可以参考完整的testdata例子:kratos/tool/kratos-gen-bts/testdata -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/kratos-genmc.md b/docs/kratos-genmc.md similarity index 98% rename from doc/wiki-cn/kratos-genmc.md rename to docs/kratos-genmc.md index 76a453bca..d83378c4d 100644 --- a/doc/wiki-cn/kratos-genmc.md +++ b/docs/kratos-genmc.md @@ -66,6 +66,3 @@ func noneKey() string { 也可以参考完整的testdata例子:kratos/tool/kratos-gen-mc/testdata -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/kratos-protoc.md b/docs/kratos-protoc.md similarity index 96% rename from doc/wiki-cn/kratos-protoc.md rename to docs/kratos-protoc.md index 02fe0d79a..78273fa3e 100644 --- a/doc/wiki-cn/kratos-protoc.md +++ b/docs/kratos-protoc.md @@ -26,6 +26,3 @@ protoc --proto_path=$GOPATH --proto_path=$GOPATH/github.com/go-kratos/kratos/thi protoc --proto_path=$GOPATH --proto_path=$GOPATH/github.com/go-kratos/kratos/third_party --proto_path=. --ecode_out=:. api.proto ``` -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/kratos-swagger.md b/docs/kratos-swagger.md similarity index 85% rename from doc/wiki-cn/kratos-swagger.md rename to docs/kratos-swagger.md index 4c7401960..6d28b3f2d 100644 --- a/doc/wiki-cn/kratos-swagger.md +++ b/docs/kratos-swagger.md @@ -6,6 +6,3 @@ kratos tool swagger serve api/api.swagger.json 同时也可以查看更多的 [go-swagger](https://github.com/go-swagger/go-swagger) 官方参数进行使用。 -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/kratos-tool.md b/docs/kratos-tool.md similarity index 96% rename from doc/wiki-cn/kratos-tool.md rename to docs/kratos-tool.md index e72028234..3bb45a4f2 100644 --- a/doc/wiki-cn/kratos-tool.md +++ b/docs/kratos-tool.md @@ -92,8 +92,6 @@ swagger(已安装): swagger api文档 Author(goswagger.io) [2019/05/05] 执行工具: kratos tool demo 安装全部工具: kratos tool install all 全部升级: kratos tool upgrade all - -详细文档: https://github.com/go-kratos/kratos/blob/master/doc/wiki-cn/kratos-tool.md ``` > 小小说明:如未安装工具,第一次运行也可自动安装,不需要特别执行install @@ -106,6 +104,3 @@ swagger(已安装): swagger api文档 Author(goswagger.io) [2019/05/05] * [genmc](kratos-genmc.md) 用于自动生成memcached缓存代码; * [genbts](kratos-genbts.md) 用于生成缓存回源代码生成,如果miss则调用回源函数从数据源获取,然后塞入缓存; -------------- - -[文档目录树](summary.md) diff --git a/docs/log-agent.md b/docs/log-agent.md new file mode 100644 index 000000000..e69de29bb diff --git a/doc/wiki-cn/logger.md b/docs/logger.md similarity index 94% rename from doc/wiki-cn/logger.md rename to docs/logger.md index 105fd5f6d..6c30bb1c1 100644 --- a/doc/wiki-cn/logger.md +++ b/docs/logger.md @@ -32,6 +32,3 @@ func main() { ## 扩展阅读 * [log-agent](log-agent.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/protoc.md b/docs/protoc.md similarity index 97% rename from doc/wiki-cn/protoc.md rename to docs/protoc.md index 1d9ff92d5..4676154c0 100644 --- a/doc/wiki-cn/protoc.md +++ b/docs/protoc.md @@ -24,6 +24,3 @@ protoc -I$GOPATH/src:$KRATOS_HOME/tool/protobuf/pkg/extensions:$KRATOS_DEMO/api 请注意替换`/Users/felix/work/go/src`目录为你本地开发环境对应GOPATH目录,其中`--gogofast_out`意味着告诉`protoc`工具需要使用`gogo protobuf`的工具生成代码。 -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/quickstart.md b/docs/quickstart.md similarity index 98% rename from doc/wiki-cn/quickstart.md rename to docs/quickstart.md index e1da9a541..cfd7a917d 100644 --- a/doc/wiki-cn/quickstart.md +++ b/docs/quickstart.md @@ -67,6 +67,3 @@ go build [kratos工具](kratos-tool.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/ratelimit.md b/docs/ratelimit.md similarity index 93% rename from doc/wiki-cn/ratelimit.md rename to docs/ratelimit.md index 51d28a76d..17f58c6aa 100644 --- a/doc/wiki-cn/ratelimit.md +++ b/docs/ratelimit.md @@ -25,7 +25,7 @@ kratos 借鉴了 Sentinel 项目的自适应限流系统,通过综合分析服 在自适应限流保护中,采集到的指标的时效性非常强,系统只需要采集最近一小段时间内的 qps、rt 即可,对于较老的数据,会自动丢弃。为了实现这个效果,kratos 使用了滑动窗口来保存采样数据。 -![ratelimit-rolling-window](/doc/img/ratelimit-rolling-window.png) +![ratelimit-rolling-window](img/ratelimit-rolling-window.png) 如上图,展示了一个具有两个桶(bucket)的滑动窗口(rolling window)。整个滑动窗口用来保存最近 1s 的采样数据,每个小的桶用来保存 500ms 的采样数据。 当时间流动之后,过期的桶会自动被新桶的数据覆盖掉,在图中,在 1000-1500ms 时,bucket 1 的数据因为过期而被丢弃,之后 bucket 3 的数据填到了窗口的头部。 @@ -45,7 +45,7 @@ windows 表示一秒内采样窗口的数量,默认配置中是 5s 50 个采 场景1,请求以每秒增加1个的速度不停上升,压测效果如下: -![ratelimit-benchmark-up-1](/doc/img/ratelimit-benchmark-up-1.png) +![ratelimit-benchmark-up-1](img/ratelimit-benchmark-up-1.png) 左测是没有限流的压测效果,右侧是带限流的压测效果。 可以看到,没有限流的场景里,系统在 700qps 时开始抖动,在 1k qps 时被拖垮,几乎没有新的请求能被放行,然而在使用限流之后,系统请求能够稳定在 600 qps 左右,rt 没有暴增,服务也没有被打垮,可见,限流有效的保护了服务。 @@ -55,6 +55,3 @@ windows 表示一秒内采样窗口的数量,默认配置中是 5s 50 个采 [Sentinel 系统自适应限流](https://github.com/alibaba/Sentinel/wiki/%E7%B3%BB%E7%BB%9F%E8%87%AA%E9%80%82%E5%BA%94%E9%99%90%E6%B5%81) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/trace.md b/docs/trace.md similarity index 98% rename from doc/wiki-cn/trace.md rename to docs/trace.md index f486e5843..34cd5e4a9 100644 --- a/doc/wiki-cn/trace.md +++ b/docs/trace.md @@ -39,4 +39,4 @@ func main(){ ### zipkin效果图 -![zipkin](/doc/img/zipkin.jpg) +![zipkin](img/zipkin.jpg) diff --git a/doc/wiki-cn/ut-support.md b/docs/ut-support.md similarity index 98% rename from doc/wiki-cn/ut-support.md rename to docs/ut-support.md index 48c0eff68..789d25f48 100644 --- a/doc/wiki-cn/ut-support.md +++ b/docs/ut-support.md @@ -146,7 +146,7 @@ func TestUsers(t *testing.T) { ``` #### 使用建议 -强烈建议使用 [testgen](https://github.com/go-kratos/kratos/blob/master/doc/wiki-cn/ut-testgen.md) 进行测试用例的生成,生成后每个方法将包含一个符合以下规范的正向用例。 +强烈建议使用 [testgen](ut-testgen.md) 进行测试用例的生成,生成后每个方法将包含一个符合以下规范的正向用例。 用例规范: 1. 每个方法至少包含一个测试方法(命名为Test[PackageName][FunctionName]) @@ -169,6 +169,7 @@ func TestUsers(t *testing.T) { #### 使用示例 1. 上层包对下层包依赖示例 Service层对Dao层依赖: + ```GO // 原方法 func (s *Service) realnameAlipayApply(c context.Context, mid int64) (info *model.RealnameAlipayApply, err error) { @@ -178,7 +179,7 @@ func (s *Service) realnameAlipayApply(c context.Context, mid int64) (info *model ... return } - + // 测试方法 func TestServicerealnameAlipayApply(t *testing.T) { convey.Convey("realnameAlipayApply", t, func(ctx convey.C) { @@ -198,8 +199,8 @@ func TestServicerealnameAlipayApply(t *testing.T) { } ``` 2. 基础库错误Mock示例 + ```Go - // 原方法(部分) func (d *Dao) BaseInfoCache(c context.Context, mid int64) (info *model.BaseInfo, err error) { ... @@ -213,8 +214,7 @@ func (d *Dao) BaseInfoCache(c context.Context, mid int64) (info *model.BaseInfo, ... return } - - + // 测试方法(错误Mock部分) func TestDaoBaseInfoCache(t *testing.T) { convey.Convey("BaseInfoCache", t, func(ctx convey.C) { @@ -232,6 +232,7 @@ func TestDaoBaseInfoCache(t *testing.T) { }) } ``` + #### 注意事项 - Monkey非线程安全 - Monkey无法针对Inline方法打补丁,在测试时可以使用go test -gcflags=-l来关闭inline编译的模式(一些简单的go inline介绍戳这里) @@ -269,9 +270,10 @@ func TestDaoBaseInfoCache(t *testing.T) { 使用示例: 1. net/http 标准库 HTTP 请求Mock + ```Go import gock "gopkg.in/h2non/gock.v1" - + // 原方法 func (d *Dao) Upload(c context.Context, fileName, fileType string, expire int64, body io.Reader) (location string, err error) { ... @@ -288,8 +290,7 @@ import gock "gopkg.in/h2non/gock.v1" ... return } - - + // 测试方法 func TestDaoUpload(t *testing.T) { convey.Convey("Upload", t, func(ctx convey.C) { @@ -348,6 +349,7 @@ func httpMock(method, url string) *gock.Request { } ``` 2. blademaster库HTTP请求Mock + ```Go // 原方法 func (d *Dao) SendWechatToGroup(c context.Context, chatid, msg string) (err error) { @@ -360,7 +362,7 @@ func (d *Dao) SendWechatToGroup(c context.Context, chatid, msg string) (err erro } return } - + // 测试方法 func TestDaoSendWechatToGroup(t *testing.T) { convey.Convey("SendWechatToGroup", t, func(ctx convey.C) { @@ -393,7 +395,7 @@ func TestDaoSendWechatToGroup(t *testing.T) { }) }) } - + func httpMock(method, url string) *gock.Request { r := gock.New(url) r.Method = strings.ToUpper(method) @@ -435,6 +437,7 @@ mockgen -destination=$GOPATH/kratos/app/xxx/dao/dao_mock.go -package=dao kratos/ ./creater --m mock absolute/path/to/your/pkg ``` - 测试代码内使用方法 + ```Go // 测试用例内直接使用 // 需引入的包 @@ -464,7 +467,7 @@ func TestPkgFoo(t *testing.T) { ... }) } - + // 可以利用Convey执行顺序方式适当调整以简化代码 func TestPkgFoo(t *testing.T) { convey.Convey("Foo", t, func(ctx convey.C) { diff --git a/doc/wiki-cn/ut-testcli.md b/docs/ut-testcli.md similarity index 100% rename from doc/wiki-cn/ut-testcli.md rename to docs/ut-testcli.md diff --git a/doc/wiki-cn/ut-testgen.md b/docs/ut-testgen.md similarity index 92% rename from doc/wiki-cn/ut-testgen.md rename to docs/ut-testgen.md index 890992ae8..c13f90a3a 100644 --- a/doc/wiki-cn/ut-testgen.md +++ b/docs/ut-testgen.md @@ -43,10 +43,3 @@ $GOPATH/bin/testgen --m mock YOUR_PROJECT/dao #仅传入包路径即可 ```shell $GOPATH/bin/testgen --m monkey yourCodeDirPath #仅传入包路径即可 ``` -### 赋诗一首 -``` -莫生气 莫生气 -代码辣鸡非我意 -自己动手分田地 -谈笑风生活长命 -``` \ No newline at end of file diff --git a/doc/wiki-cn/ut.md b/docs/ut.md similarity index 87% rename from doc/wiki-cn/ut.md rename to docs/ut.md index 9a73d15c6..8907f0517 100644 --- a/doc/wiki-cn/ut.md +++ b/docs/ut.md @@ -30,9 +30,3 @@ golang 的单元测试,既可以用官方自带的 testing 包,也有开源 > - 基础组件,如mc、redis、mysql等,由 testcli(testing/lich) 起基础镜像支持(需要提供建表、INSERT语句)与本地开发环境一致,也保证了结果的一致性。 > - rpc server,如 xxxx-service 需要定义 interface 供业务依赖方使用。所有rpc server 都必须要提供一个interface+mock代码(gomock)。 > - http server则直接写mock代码gock。 - -# 注意 -单元测试极其重要,良好的单元测试习惯能很大程度上避免代码变更引起的bug! -单元测试极其重要,良好的单元测试习惯能很大程度上避免代码变更引起的bug! -单元测试极其重要,良好的单元测试习惯能很大程度上避免代码变更引起的bug! -以为很重要所以重复 3 遍~ \ No newline at end of file diff --git a/doc/wiki-cn/warden-balancer.md b/docs/warden-balancer.md similarity index 95% rename from doc/wiki-cn/warden-balancer.md rename to docs/warden-balancer.md index 7ca6e30bb..5ffc9ee68 100644 --- a/doc/wiki-cn/warden-balancer.md +++ b/docs/warden-balancer.md @@ -37,7 +37,3 @@ func NewClient(conf *ClientConfig, opt ...grpc.DialOption) *Client { return c } ``` - -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/warden-mid.md b/docs/warden-mid.md similarity index 99% rename from doc/wiki-cn/warden-mid.md rename to docs/warden-mid.md index 8afcfdb33..b477a99bb 100644 --- a/doc/wiki-cn/warden-mid.md +++ b/docs/warden-mid.md @@ -324,7 +324,7 @@ func serverLogging() grpc.UnaryServerInterceptor { ## 自适应限流拦截器 -更多关于自适应限流的信息,请参考:[kratos 自适应限流](/doc/wiki-cn/ratelimit.md) +更多关于自适应限流的信息,请参考:[kratos 自适应限流](ratelimit.md) ```go package grpc @@ -369,8 +369,3 @@ func New(svc *service.Service) *warden.Server { # 扩展阅读 [warden快速开始](warden-quickstart.md) [warden基于pb生成](warden-pb.md) [warden负载均衡](warden-balancer.md) [warden服务发现](warden-resolver.md) - -------------- - -[文档目录树](summary.md) - diff --git a/doc/wiki-cn/warden-pb.md b/docs/warden-pb.md similarity index 97% rename from doc/wiki-cn/warden-pb.md rename to docs/warden-pb.md index ca8856de8..676b3a78f 100644 --- a/doc/wiki-cn/warden-pb.md +++ b/docs/warden-pb.md @@ -42,6 +42,3 @@ func (s *Service) SayHelloURL(ctx context.Context, req *pb.HelloReq) (reply *pb. [warden快速开始](warden-quickstart.md) [warden拦截器](warden-mid.md) [warden负载均衡](warden-balancer.md) [warden服务发现](warden-resolver.md) -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/warden-quickstart.md b/docs/warden-quickstart.md similarity index 99% rename from doc/wiki-cn/warden-quickstart.md rename to docs/warden-quickstart.md index 9ce395d39..6173ebd55 100644 --- a/doc/wiki-cn/warden-quickstart.md +++ b/docs/warden-quickstart.md @@ -169,7 +169,3 @@ func (d *Dao) SayHello(c context.Context, req *demoapi.HelloReq) (resp *grpcempt [warden基于pb生成](warden-pb.md) [warden服务发现](warden-resolver.md) [warden负载均衡](warden-balancer.md) - -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/warden-resolver.md b/docs/warden-resolver.md similarity index 99% rename from doc/wiki-cn/warden-resolver.md rename to docs/warden-resolver.md index 8304dca0c..5ea99ca62 100644 --- a/doc/wiki-cn/warden-resolver.md +++ b/docs/warden-resolver.md @@ -249,7 +249,3 @@ etcd默认的全局keyPrefix为kratos_etcd,当该keyPrefix与项目中其他keyP # 扩展阅读 [warden快速开始](warden-quickstart.md) [warden拦截器](warden-mid.md) [warden基于pb生成](warden-pb.md) [warden负载均衡](warden-balancer.md) - -------------- - -[文档目录树](summary.md) diff --git a/doc/wiki-cn/warden.md b/docs/warden.md similarity index 96% rename from doc/wiki-cn/warden.md rename to docs/warden.md index 9c2782564..56c4e8600 100644 --- a/doc/wiki-cn/warden.md +++ b/docs/warden.md @@ -35,6 +35,3 @@ gRPC暴露了两个拦截器接口,分别是: [warden快速开始](warden-quickstart.md) [warden拦截器](warden-mid.md) [warden负载均衡](warden-balancer.md) [warden基于pb生成](warden-pb.md) [warden服务发现](warden-resolver.md) -------------- - -[文档目录树](summary.md)