Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add docs for request id middleware #379

Merged
merged 10 commits into from
Oct 28, 2022
Merged

doc: add docs for request id middleware #379

merged 10 commits into from
Oct 28, 2022

Conversation

justlorain
Copy link
Member

What type of PR is this?

docs

What this PR does / why we need it (en: English/zh: Chinese):

en: add docs for Request ID middleware
zh: 添加Request ID中间件的文档

@li-jin-gou
Copy link
Member

li-jin-gou commented Oct 11, 2022

可以参考 jwt 的 pr #369 优化修改一下哈

@li-jin-gou li-jin-gou changed the title [WIP]doc: add docs for request id middleware doc: add docs for request id middleware Oct 13, 2022
函数签名:

```go
// Generator类型是func() string的别名
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

英文和中文之间缺少空格,很多注释里都有这个问题,请仔细查看

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thx


上述**示例代码**中,只传入了两项自定义的配置。关于 `config` 的更多常用配置如下:

| 参数 | 介绍 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为使用了 functional option 的方式,config struct 默认是隐藏的,这样突然进行说明其实显得很突兀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

## 配置

Hertz 通过使用中间件,可以在响应头中添加一个键为 `X-Request-ID` 的标识符,如果在请求头中设置了 `X-Request-ID` 字段,则会在响应头中将 `X-Request-ID` 原样返回。
其中 `config` 结构体定义了 Request ID 的配置信息,并提供了默认配置,用户也可以依据业务场景进行定制。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该不描述 config struct,该改一下描述了

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


---

`X-Request-ID` 是一种HTTP非标准响应字段,通常用来关联客户端和服务器之间的HTTP请求。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X-Request-ID 是一种HTTP非标准响应字段,通常用来关联客户端和服务器之间的HTTP请求。 ->

X-Request-ID 在 HTTP Headers 中是一种非标准响应字段,通常用于关联客户端和服务器之间的 HTTP 请求。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

---

`X-Request-ID` 是一种HTTP非标准响应字段,通常用来关联客户端和服务器之间的HTTP请求。
Hertz 也提供了 Request ID 的[实现](https://github.com/hertz-contrib/requestid),参考了 gin 的[实现](https://github.com/gin-contrib/requestid)。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

语序有些问题,阅读起来不是很流畅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)

func main() {
h := server.Default()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码缩进有些问题。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thx

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


| configuration | Description |
|---------------|--------------------------------------------------------------------------------------------|
| generator | Define a function that generates a Request ID. By default, a UUID identifier is generated. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方 WIth*** 吧 因为是配置介绍,但是属性都是私有的

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx

@GuangmingLuo GuangmingLuo merged commit 987780f into cloudwego:main Oct 28, 2022
YUandJIANG pushed a commit to YUandJIANG/cloudwego.github.io that referenced this pull request Nov 10, 2022
* [WIP]doc: add docs for request id middleware

* standardize code format

* improve request id doc

* standardizing doc

* change weight

* improve requestid doc by cr

* Optimize code indentation

* fix typo

* improve document readability

* format code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

6 participants