|
| 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 |
0 commit comments