Skip to content

Commit f2eab33

Browse files
authored
feat: hertz v0.7.0 (#823)
1 parent 56e2962 commit f2eab33

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: "Hertz Release v0.7.0"
3+
linkTitle: "Release v0.7.0"
4+
projects: ["Hertz"]
5+
date: 2023-09-26
6+
description: >
7+
---
8+
9+
In version 0.7.0 of Hertz, in addition to regular iterative optimization, we also brought several important features.
10+
11+
## Refactor Binding
12+
In version 0.7.0 of Hertz,we refactored the binding feature for Hertz
13+
>https://github.com/cloudwego/hertz/pull/541
14+
15+
### Description Of Refactoring
16+
In version 0.7.0 of Hertz,we refactored the binding feature for Hertz to better support user requirements。This refactoring has the following characteristics:
17+
* Consistent functionality:
18+
- Binder: After the refactoring, we have implemented a default Binder within Hertz, which has the same functionality as before. The previous binding capabilities have been implemented as extensions under hertz-contrib.
19+
- Validator: We are still using go-tagexpr as the default implementation to ensure consistent functionality.
20+
* Converged configuration:
21+
- Before the refactoring, the behavior of parameter binding was mostly configured through global parameters, which could lead to conflicts when multiple components were configured.
22+
- After the refactoring, the binding and validation configurations are injected into the Hertz Engine through `BindConfig` and `ValidateConfig` struct using the 'WithOption' function. This not only unifies the configuration format but also avoids configuration conflicts.
23+
* Customizable Binder and Validator:
24+
- Custom Binder: You can use "WithCustomBinder" to inject your own custom Binder. We have already provided an extension called hertz-contrib/binding/go_tagexpr.
25+
- Custom Validator: You can use "WithCustomValidator" to inject your own custom Validator. We have also extended go-playground/validator for this purpose.
26+
* Performance improvements: The refactoring has resulted in improved binding performance compared to the previous version. Please refer to the benchmark data below for more details.
27+
28+
29+
### Usage
30+
```go
31+
package main
32+
33+
import (
34+
"github.com/cloudwego/hertz/pkg/app/server/binding"
35+
"github.com/cloudwego/hertz/pkg/app/server"
36+
)
37+
38+
func main() {
39+
bindConfig := binding.NewBindConfig()
40+
bindConfig.LooseZeroMode = true
41+
h := server.New(server.WithBindConfig(bindConfig))
42+
...
43+
h.Spin()
44+
}
45+
```
46+
47+
### Benchmark Data
48+
https://github.com/cloudwego/hertz-benchmark/tree/main/binding
49+
50+
## Full Release Note
51+
52+
The complete Release Note can refer to:
53+
* Hertz: https://github.com/cloudwego/hertz/releases/tag/v0.7.0
54+
* Hz(scaffolding): https://github.com/cloudwego/hertz/releases/tag/cmd%2Fhz%2Fv0.7.0
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
title: "Hertz v0.7.0 版本发布"
3+
linkTitle: "Release v0.7.0"
4+
projects: ["Hertz"]
5+
date: 2023-09-26
6+
description: >
7+
---
8+
9+
Hertz v0.7.0 版本中,除了常规迭代优化之外,我们还带来了一个重要 feature。
10+
11+
## 参数绑定重构
12+
在 Hertz v0.7.0 版本中,我们重构了 hertz 参数绑定
13+
>https://github.com/cloudwego/hertz/pull/541
14+
15+
### 重构说明
16+
在 Hertz v0.7.0 版本中,我们重构了参数绑定能力,将参数绑定能力收敛到框架本身,以更好地支持用户的需求。本次重构主要有以下特点:
17+
* 功能一致:
18+
- Binder:重构后在 Hertz 内部实现了一个默认的 Binder,其功能与重构前完全对齐,并将重构前的绑定能力以拓展的形式实现在 hertz-contrib 下
19+
- Validator: 仍使用 go-tagexpr 作为默认实现,保证功能一致
20+
* 配置收敛:
21+
- 重构前:参数绑定的行为大多通过全局参数的形式进行配置,可能导致多个组件出现配置冲突
22+
- 重构后:以 BindConfig 和 ValidateConfig 的结构通过 'WithOption' 的形式注入到 Hertz Engine 中,既能统一配置形式,又能避免配置冲突的问题
23+
* 可自定义 Binder 和 Validator:
24+
- 自定义 Binder:可使用 "WithCustomBinder" 来注入自定义的 Binder,目前已有拓展 hertz-contrib/binding/go_tagexpr
25+
- 自定义 Validator:可使用 "WithCustomValidator" 来注入自定义的 Validator,目前已经将 go-playground/validator 进行了拓展
26+
* 性能提升:重构后绑定性能较之前有提升,详见后文压测数据
27+
28+
### 使用方法
29+
```go
30+
package main
31+
32+
import (
33+
"github.com/cloudwego/hertz/pkg/app/server/binding"
34+
"github.com/cloudwego/hertz/pkg/app/server"
35+
)
36+
37+
func main() {
38+
bindConfig := binding.NewBindConfig()
39+
bindConfig.LooseZeroMode = true
40+
h := server.New(server.WithBindConfig(bindConfig))
41+
...
42+
h.Spin()
43+
}
44+
```
45+
46+
### 压测数据
47+
https://github.com/cloudwego/hertz-benchmark/tree/main/binding
48+
49+
完整的 Release Note 可以参考:
50+
* Hertz: https://github.com/cloudwego/hertz/releases/tag/v0.7.0
51+
* Hz(脚手架): https://github.com/cloudwego/hertz/releases/tag/cmd%2Fhz%2Fv0.7.0

0 commit comments

Comments
 (0)