Skip to content

Commit

Permalink
docs: optimize hertz vd tag description
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoranz758 committed Mar 4, 2024
1 parent 351ce08 commit e808dba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,21 @@ If [api-annotations](/docs/hertz/tutorials/toolkit/annotation/#supported-api-ann
| json | This tag is used to bind json parameters in the request body which content-type is `application/json` |
| raw_body | This tag is used to bind the original body (bytes type) of the request, and parameters can be bound even if the bound field name is not specified. (Note: raw_body has the lowest binding priority. When multiple tags are specified, once other tags successfully bind parameters, the body content will not be bound) |
| vd | `vd` short for validator, [The grammar of validation parameter](https://github.com/bytedance/go-tagexpr/tree/master/validator) |
| default | Set default value |
| default | Set default value

### Parameter Validation

Specific validation syntax can be referred to [The grammar of validation parameter](https://github.com/bytedance/go-tagexpr/tree/master/validator).

When generating code without IDL, directly tag the corresponding structure field, for example:

```go
type InfoRequest struct {
Name string `vd:"$!='your string'"`
}
```

When generating code through IDL, corresponding annotations need to be added, please refer to [field-annotation](/docs/hertz/tutorials/toolkit/annotation/#field-annotation).

### Parameter binding precedence

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ func main() {
| vd | 参数校验,[校验语法](https://github.com/bytedance/go-tagexpr/tree/master/validator) |
| default | 设置默认值 |

### 参数校验

具体校验语法可参考[校验语法](https://github.com/bytedance/go-tagexpr/tree/master/validator)

不通过 IDL 生成代码时直接在对应结构体字段打 tag,示例:

```go
type InfoRequest struct {
Name string `vd:"$!='your string'"`
}
```

通过 IDL 生成代码时需添加相应的注解,可参考[Field 注解](/zh/docs/hertz/tutorials/toolkit/annotation/#field-注解)

### 参数绑定优先级

```text
Expand Down

0 comments on commit e808dba

Please sign in to comment.