Skip to content

Commit

Permalink
增加文档
Browse files Browse the repository at this point in the history
  • Loading branch information
askuy committed Jan 25, 2024
1 parent 4dbb229 commit af635e2
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 33 deletions.
10 changes: 9 additions & 1 deletion docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,15 @@ var _hmt = _hmt || [];
},
], //这样自动生成对应文章
"/practice/": [
"debug",
{
title: "第一章 调试和错误处理",
collapsable: false, // 可选的, 默认值是 true,
children: [
"chapter1/debug",
"chapter1/egotrace",
"chapter1/error",
],
},
],
"/micro/": [
"大纲",
Expand Down
36 changes: 18 additions & 18 deletions docs/awesome/egov1.0.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,24 @@ go get github.com/ego-component/[email protected]

| Component Name | Code | Example | Doc |
|---------------------------|----------------------------------------------------------------------|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| HTTP Server | [Code](https://github.com/gotomicro/ego/tree/master/server/egin) | [Example](https://github.com/gotomicro/ego/tree/master/examples/server/http) | [Doc](https://ego.gocn.vip/frame/server/http.html) |
| gRPC Server | [Code](https://github.com/gotomicro/ego/tree/master/server/egrpc) | [Example](https://github.com/gotomicro/ego/tree/master/examples/server/grpc) | [Doc](https://ego.gocn.vip/frame/server/grpc.html#example) |
| Governance Service | [Code](https://github.com/gotomicro/ego/tree/master/server/egovernor) | [Example](https://github.com/gotomicro/ego/tree/master/examples/server/governor) | [Doc](https://ego.gocn.vip/frame/server/governor.html) |
| Job | [Code](https://github.com/gotomicro/ego/tree/master/task/ejob) | [Example](https://github.com/gotomicro/ego/tree/master/examples/task/job) | [Doc](https://ego.gocn.vip/frame/task/job.html) |
| Corn job | [Code](https://github.com/gotomicro/ego/tree/master/task/ecron) | [Example](https://github.com/gotomicro/ego/tree/master/examples/task/cron) | [Doc](https://ego.gocn.vip/frame/task/cron.html#_3-%E5%B8%B8%E8%A7%84%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1) |
| Distributed Scheduled Job | [Code](https://github.com/gotomicro/ego/tree/master/task/ecron) | [Example](https://github.com/gotomicro/ego/tree/master/examples/task/cron) | [Doc](https://ego.gocn.vip/frame/task/cron.html#_4-%E5%88%86%E5%B8%83%E5%BC%8F%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1) |
| HTTP Client | [Code](https://github.com/gotomicro/ego/tree/master/client/ehttp) | [Example](https://github.com/gotomicro/ego/tree/master/examples/http/client) | [Doc](https://ego.gocn.vip/frame/client/http.html#example) |
| gRPC Client | [Code](https://github.com/gotomicro/ego/tree/master/client/egrpc) | [Example](https://github.com/gotomicro/ego/tree/master/examples/grpc/direct) | [Doc](https://ego.gocn.vip/frame/client/grpc.html#_4-%E7%9B%B4%E8%BF%9Egrpc) |
| gRPC Client using ETCD | [Code](https://github.com/ego-component/tree/master/eetcd) | [Example](https://github.com/ego-component/tree/master/eetcd/examples) | [Doc](https://ego.gocn.vip/frame/client/grpc.html#_5-%E4%BD%BF%E7%94%A8etcd%E7%9A%84grpc) |
| gRPC Client using k8s | [Code](https://github.com/ego-component/tree/master/ek8s) | [Example](https://github.com/ego-component/tree/master/ek8s/examples) | [Doc](https://ego.gocn.vip/frame/client/grpc.html#_6-%E4%BD%BF%E7%94%A8k8s%E7%9A%84grpc) |
| Sentinel | [Code](https://github.com/gotomicro/ego/tree/master/core/esentinel) | [Example](https://github.com/gotomicro/ego/tree/master/examples/sentinel/http) | [Doc](https://ego.gocn.vip/frame/client/sentinel.html) |
| MySQL | [Code](https://github.com/ego-component/tree/master/egorm) | [Example](https://github.com/ego-component/tree/master/egorm/examples) | [Doc](https://ego.gocn.vip/frame/client/gorm.html#example) |
| Redis | [Code](https://github.com/ego-component/tree/master/eredis) | [Example](https://github.com/ego-component/tree/master/eredis/examples) | [Doc](https://ego.gocn.vip/frame/client/redis.html#example) |
| Redis Distributed lock | [Code](https://github.com/ego-component/tree/master/eredis) | [Example](https://github.com/ego-component/tree/master/eredis/examples) | [Doc](https://ego.gocn.vip/frame/client/redis.html#example) |
| Mongo | [Code](https://github.com/ego-component/tree/master/emongo) | [Example](https://github.com/ego-component/tree/master/emongo/examples) | [Doc](https://ego.gocn.vip/frame/client/mongo.html) |
| Kafka | [Code](https://github.com/ego-component/tree/master/ekafka) | [Example](https://github.com/ego-component/tree/master/ekafka/examples) | [Doc](https://ego.gocn.vip/frame/client/kafka.html) |
| ETCD | [Code](https://github.com/ego-component/tree/master/eetcd) | [Example](https://github.com/ego-component/tree/master/eetcd/examples) | [Doc](https://ego.gocn.vip/frame/client/eetcd.html) |
| K8S | [Code](https://github.com/ego-component/tree/master/ek8s) | [Example](https://github.com/ego-component/tree/master/ek8s/examples) | [Doc](https://ego.gocn.vip/frame/client/ek8s.html) |
| HTTP Server | [Code](https://github.com/gotomicro/ego/tree/master/server/egin) | [Example](https://github.com/gotomicro/ego/tree/master/examples/server/http) | [Doc](https://ego-org.com/frame/server/http.html) |
| gRPC Server | [Code](https://github.com/gotomicro/ego/tree/master/server/egrpc) | [Example](https://github.com/gotomicro/ego/tree/master/examples/server/grpc) | [Doc](https://ego-org.com/frame/server/grpc.html#example) |
| Governance Service | [Code](https://github.com/gotomicro/ego/tree/master/server/egovernor) | [Example](https://github.com/gotomicro/ego/tree/master/examples/server/governor) | [Doc](https://ego-org.com/frame/server/governor.html) |
| Job | [Code](https://github.com/gotomicro/ego/tree/master/task/ejob) | [Example](https://github.com/gotomicro/ego/tree/master/examples/task/job) | [Doc](https://ego-org.com/frame/task/job.html) |
| Corn job | [Code](https://github.com/gotomicro/ego/tree/master/task/ecron) | [Example](https://github.com/gotomicro/ego/tree/master/examples/task/cron) | [Doc](https://ego-org.com/frame/task/cron.html#_3-%E5%B8%B8%E8%A7%84%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1) |
| Distributed Scheduled Job | [Code](https://github.com/gotomicro/ego/tree/master/task/ecron) | [Example](https://github.com/gotomicro/ego/tree/master/examples/task/cron) | [Doc](https://ego-org.com/frame/task/cron.html#_4-%E5%88%86%E5%B8%83%E5%BC%8F%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1) |
| HTTP Client | [Code](https://github.com/gotomicro/ego/tree/master/client/ehttp) | [Example](https://github.com/gotomicro/ego/tree/master/examples/http/client) | [Doc](https://ego-org.com/frame/client/http.html#example) |
| gRPC Client | [Code](https://github.com/gotomicro/ego/tree/master/client/egrpc) | [Example](https://github.com/gotomicro/ego/tree/master/examples/grpc/direct) | [Doc](https://ego-org.com/frame/client/grpc.html#_4-%E7%9B%B4%E8%BF%9Egrpc) |
| gRPC Client using ETCD | [Code](https://github.com/ego-component/tree/master/eetcd) | [Example](https://github.com/ego-component/tree/master/eetcd/examples) | [Doc](https://ego-org.com/frame/client/grpc.html#_5-%E4%BD%BF%E7%94%A8etcd%E7%9A%84grpc) |
| gRPC Client using k8s | [Code](https://github.com/ego-component/tree/master/ek8s) | [Example](https://github.com/ego-component/tree/master/ek8s/examples) | [Doc](https://ego-org.com/frame/client/grpc.html#_6-%E4%BD%BF%E7%94%A8k8s%E7%9A%84grpc) |
| Sentinel | [Code](https://github.com/gotomicro/ego/tree/master/core/esentinel) | [Example](https://github.com/gotomicro/ego/tree/master/examples/sentinel/http) | [Doc](https://ego-org.com/frame/client/sentinel.html) |
| MySQL | [Code](https://github.com/ego-component/tree/master/egorm) | [Example](https://github.com/ego-component/tree/master/egorm/examples) | [Doc](https://ego-org.com/frame/client/gorm.html#example) |
| Redis | [Code](https://github.com/ego-component/tree/master/eredis) | [Example](https://github.com/ego-component/tree/master/eredis/examples) | [Doc](https://ego-org.com/frame/client/redis.html#example) |
| Redis Distributed lock | [Code](https://github.com/ego-component/tree/master/eredis) | [Example](https://github.com/ego-component/tree/master/eredis/examples) | [Doc](https://ego-org.com/frame/client/redis.html#example) |
| Mongo | [Code](https://github.com/ego-component/tree/master/emongo) | [Example](https://github.com/ego-component/tree/master/emongo/examples) | [Doc](https://ego-org.com/frame/client/mongo.html) |
| Kafka | [Code](https://github.com/ego-component/tree/master/ekafka) | [Example](https://github.com/ego-component/tree/master/ekafka/examples) | [Doc](https://ego-org.com/frame/client/kafka.html) |
| ETCD | [Code](https://github.com/ego-component/tree/master/eetcd) | [Example](https://github.com/ego-component/tree/master/eetcd/examples) | [Doc](https://ego-org.com/frame/client/eetcd.html) |
| K8S | [Code](https://github.com/ego-component/tree/master/ek8s) | [Example](https://github.com/ego-component/tree/master/ek8s/examples) | [Doc](https://ego-org.com/frame/client/ek8s.html) |
| Oauth2 | [Code](https://github.com/ego-component/tree/master/eoauth2) | [Example](https://github.com/ego-component/tree/master/eoauth2/examples) ||

## 欢迎大家使用EGO
Expand Down
2 changes: 1 addition & 1 deletion docs/frame/client/eetcd.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/ego-component/eetcd.svg?style=flat-square)](https://github.com/ego-component/eetcd)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Example](https://img.shields.io/badge/Examples-2ca5e0?style=flat&logo=appveyor)](https://github.com/ego-component/eetcd/tree/master/examples)
[![Doc](https://img.shields.io/badge/Docs-1?style=flat&logo=appveyor)](https://ego.gocn.vip/frame/client/eetcd.html)
[![Doc](https://img.shields.io/badge/Docs-1?style=flat&logo=appveyor)](https://ego-org.com/frame/client/eetcd.html)


## 1 简介
Expand Down
2 changes: 1 addition & 1 deletion docs/frame/client/ek8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/ego-component/ek8s.svg?style=flat-square)](https://github.com/ego-component/ek8s)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Example](https://img.shields.io/badge/Examples-2ca5e0?style=flat&logo=appveyor)](https://github.com/ego-component/ek8s/tree/master/examples)
[![Doc](https://img.shields.io/badge/Docs-1?style=flat&logo=appveyor)](https://ego.gocn.vip/frame/client/gorm.html#_1-%E7%AE%80%E4%BB%8B)
[![Doc](https://img.shields.io/badge/Docs-1?style=flat&logo=appveyor)](https://ego-org.com/frame/client/gorm.html#_1-%E7%AE%80%E4%BB%8B)

## 1 简洁
- 规范了标准配置格式,提供了统一的 Load().Build() 方法。
Expand Down
4 changes: 2 additions & 2 deletions docs/frame/client/gorm.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## 2 说明
* [example地址](https://github.com/ego-component/egorm/tree/master/examples)
* [文档地址](https://ego.gocn.vip/frame/client/gorm.html#_1-%E7%AE%80%E4%BB%8B)
* [文档地址](https://ego-org.com/frame/client/gorm.html#_1-%E7%AE%80%E4%BB%8B)
* ego版本:``[email protected]``
* egorm版本: ``[email protected]``

Expand Down Expand Up @@ -141,7 +141,7 @@ enableDetailSQL=true # 记录sql时,是否打印包含参数的完整sql

### 6.5 开启自定义日志字段的数据
在使用了ego的自定义字段功能`export EGO_LOG_EXTRA_KEYS=X-Ego-Uid`,将对应的数据塞入到context中,那么gorm的access日志就可以记录对应字段信息。
参考 [详细文档](https://ego.gocn.vip/micro/chapter2/trace.html#_6-ego-access-%E8%87%AA%E5%AE%9A%E4%B9%89%E9%93%BE%E8%B7%AF)
参考 [详细文档](https://ego-org.com/micro/chapter2/trace.html#_6-ego-access-%E8%87%AA%E5%AE%9A%E4%B9%89%E9%93%BE%E8%B7%AF)
```go
func testDB() error {
var user User
Expand Down
2 changes: 1 addition & 1 deletion docs/frame/client/mongo.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Release](https://img.shields.io/github/v/release/ego-component/emongo.svg?style=flat-square)](https://github.com/ego-component/emongo)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Example](https://img.shields.io/badge/Examples-2ca5e0?style=flat&logo=appveyor)](https://github.com/ego-component/emongo/tree/master/examples)
[![Doc](https://img.shields.io/badge/Docs-1?style=flat&logo=appveyor)](https://ego.gocn.vip/frame/client/gorm.html#_1-%E7%AE%80%E4%BB%8B)
[![Doc](https://img.shields.io/badge/Docs-1?style=flat&logo=appveyor)](https://ego-org.com/frame/client/gorm.html#_1-%E7%AE%80%E4%BB%8B)


## 1 简介
Expand Down
2 changes: 1 addition & 1 deletion docs/frame/client/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ enableAccessInterceptorRes=true # 是否开启记录响应参数

### 6.3 开启自定义日志字段的数据
在使用了ego的自定义字段功能`export EGO_LOG_EXTRA_KEYS=X-Ego-Uid`,将对应的数据塞入到context中,那么redis的access日志就可以记录对应字段信息。
参考 [详细文档](https://ego.gocn.vip/micro/chapter2/trace.html#_6-ego-access-%E8%87%AA%E5%AE%9A%E4%B9%89%E9%93%BE%E8%B7%AF)
参考 [详细文档](https://ego-org.com/micro/chapter2/trace.html#_6-ego-access-%E8%87%AA%E5%AE%9A%E4%B9%89%E9%93%BE%E8%B7%AF)
```go
func testRedis() error {
ctx := context.Background()
Expand Down
2 changes: 1 addition & 1 deletion docs/frame/core/trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func main() {
```

### 最终达到效果
[链路数据流向原理链接](https://ego.gocn.vip/micro/chapter2/trace.html)
[链路数据流向原理链接](https://ego-org.com/micro/chapter2/trace.html)

例如`MySQL``access`日志中记录了`uid``trace id`信息。
![img.png](../../images/egoaccesstrace3.png)
Expand Down
2 changes: 1 addition & 1 deletion docs/micro/chapter2/trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


以上就是Ego将日志中实现了链路的数据流向。快来体验吧。
[如何传递和使用链路,请点击链接](https://ego.gocn.vip/frame/core/trace.html)
[如何传递和使用链路,请点击链接](https://ego-org.com/frame/core/trace.html)

体验版本为:
* github.com/gotomicro/[email protected]
Expand Down
10 changes: 5 additions & 5 deletions docs/practice/debug.md → docs/practice/chapter1/debug.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 快速调试和定位错误
## 快速调试和定位错误

理想的情况下,我们都希望微服务之间的调用,能够得到正确的响应,这样我们就可以赶紧开发完代码,联通OK,早点下班。

Expand Down Expand Up @@ -124,7 +124,7 @@ resp, err := client.SayHello(ctx, &helloworld.HelloReq{
```

可以通过下图看到调试信息。相比我们上一讲的`hello world`响应,这里展示各种报错信息。
![img_3.png](../images/practice/debug_1.png)
![img_3.png](../../images/practice/debug_1.png)


红色的高亮报错非常直观,我们可以看到RPC报了系统错误,并返回了Internal错误码,而且因为调试信息中有代码的全路径,我们可以在`Goland IDE`里直接点击这个代码行号,进入到出错的代码中,直接去解决问题,节约大量修复问题的时间。
Expand Down Expand Up @@ -197,7 +197,7 @@ func debugEncodeLevel(lv zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
代码行号使用全路径的`zapcore.FullCallerEncoder`,这样编辑器可以直接点击到对应代码执行位置。由于`grpc`包中调用链套了5层,我们需要设置`NewDebugLogger().Build(zap.AddCallerSkip(5))`,这样可以正确找到`gRPC`包中执行的地方。

最后我们再执行客户端的调用,可以看到这样的调用流程信息。
![img_4.png](../images/practice/debug_2.png)
![img_4.png](../../images/practice/debug_2.png)

在图中,可以看到了整个`gRPC`的调用情况,如果出现名字服务问题或者负载均衡问题,我们就可以通过这些日志排查出问题。

Expand Down Expand Up @@ -283,11 +283,11 @@ func LoggerPanic(msg string, fields ...zap.Field) {
```
把对应的核心错误的必要信息高亮,通过panic终止程序,在最后一行显示错误。
完成了我们验证一下。假设在客户端配置一个不存在的`grpc`服务端地址`127.0.0.1:9100`,可以看到启动客户端会报详细的错误和堆栈信息。
![img_5.png](../images/practice/debug_3.png)
![img_5.png](../../images/practice/debug_3.png)


作为对比,我们使用`notpanic example`代码,同样设置一个不存在的`gRPC`地址,可以发现在日志中虽然有记录错误,但它在其他日志上面,如果业务复杂,日志非常多,刷屏后,很难发现这种核心报错信息。
![img_6.png](../images/practice/debug_4.png)
![img_6.png](../../images/practice/debug_4.png)


## 总结
Expand Down
Loading

0 comments on commit af635e2

Please sign in to comment.