Skip to content

Commit

Permalink
fix range expr
Browse files Browse the repository at this point in the history
  • Loading branch information
kesonan committed Jun 6, 2023
1 parent 2a4ab5c commit 6ab2d2e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions docs/tutorials/api/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ type Foo {

在 api 描述语言中,我们可以通过在 tag 中来声明参数接收规则,除此之外,还支持参数的校验,参数校验的规则仅对 **请求体** 有效,参数校验的规则写在 tag value中,目前 go-zero 支持的参数校验规则如下:

| <img width={100}/>接收规则 | 说明 | 示例 |
| --- | --- | --- |
| optional | 当前字段是可选参数,允许为零值(zero value) | \`json:"foo,optional"\` |
| <img width={100}/>接收规则 | 说明 | 示例 |
| --- | --- |-------------------------------------|
| optional | 当前字段是可选参数,允许为零值(zero value) | \`json:"foo,optional"\` |
| options | 当前参数仅可接收的枚举值 | \`json:"gender,options=[foo,bar]"\` |
| default | 当前参数默认值 | \`json:"gender,default=male"\` |
| range | 当前参数数值有效范围,仅对数值有效,写法规则详情见下文温馨提示 | \`json:"age,range=[0,120]"\` |
| default | 当前参数默认值 | \`json:"gender,default=male"\` |
| range | 当前参数数值有效范围,仅对数值有效,写法规则详情见下文温馨提示 | \`json:"age,range=[0:120]"\` |

:::note range 表达式值规则
1. 左开右闭区间:(min:max],表示大于 min 小于等于 max,当 min 缺省时,min 代表数值 0,当 max 缺省时,max 代表无穷大,min 和 max 不能同时缺省
Expand Down
14 changes: 7 additions & 7 deletions docs/tutorials/go-zero-configuration/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ type Config struct {

目前 go-zero 支持的校验规则如下:

| 接收规则 | 说明 | 示例 |
| -------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| optional | 当前字段是可选参数,允许为零值(zero value) | \`json:"foo,optional"\` |
| options | 当前参数仅可接收的枚举值 | **写法 1**:竖线\|分割,\`json:"gender,options=foo\|bar"\` <br/>**写法 2**:数组风格,\`json:"gender,[foo,bar]"\` |
| default | 当前参数默认值 | \`json:"gender,default=male"\` |
| range | 当前参数数值有效范围,仅对数值有效,写法规则详情见下文温馨提示 | \`json:"age,range=[0,120]"\` |
| env | 当前参数从环境变量获取 | \`json:"mode,env=MODE"\` |
| 接收规则 | 说明 | 示例 |
| -------- | -------------------------------------------------------------- |--------------------------------|
| optional | 当前字段是可选参数,允许为零值(zero value) | \`json:"foo,optional"\` |
| options | 当前参数仅可接收的枚举值 | **写法 1**:竖线\ |分割,\`json:"gender,options=foo\|bar"\` <br/>**写法 2**:数组风格,\`json:"gender,[foo,bar]"\` |
| default | 当前参数默认值 | \`json:"gender,default=male"\` |
| range | 当前参数数值有效范围,仅对数值有效,写法规则详情见下文温馨提示 | \`json:"age,range=[0:120]"\` |
| env | 当前参数从环境变量获取 | \`json:"mode,env=MODE"\` |

:::note range 表达式值规则
1. 左开右闭区间:(min:max],表示大于 min 小于等于 max,当 min 缺省时,min 代表数值 0,当 max 缺省时,max 代表无穷大,min 和 max 不能同时缺省
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ type Foo {

In the api description language, we can state the acceptance rules for parameters in a tag in a tag. In addition to this we also support the verification of parameters, which are valid only for **request** , the parameter validation rule is written in tag value, currently supported by go-zero the following parameters:

| <img width={100} />Receive rules | Note | Sample |
| ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | --------------------------------------- |
| <img width={100} />Receive rules | Note | Sample |
| ------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |-------------------------------------|
| optional | The current field is an optional parameter, allowing zero value (zero value) | \`json:"foo,optional"\` |
| options | Current parameter can only receive an enumeration value | \`json:"gender,options=[foo,bar]"\` |
| default | Current Argument Default | \`json:"gender,default=male"\` |
| range | The valid range of the current parameter value, only valid for the value. Details of the writing rule are given below | \`json:"age,range=[0,120]"\` |
| range | The valid range of the current parameter value, only valid for the value. Details of the writing rule are given below | \`json:"age,range=[0:120]"\` |

::note range expressed value rule
1. Left close interval:(min:max], meaning that min is less than or equal to max, when min is default, min represents value 0, max is unlimited when max is default, min and max are not allowed to default at the same time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ If we are loading in conf the verification is not passed, the corresponding erro

The currently supported verification rules for go-zero are as follows:

| Receive rules | Note | Sample |
| ------------- | --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| optional | The current field is an optional parameter, allowing zero value (zero value) | \`json:"foo,optional"\` |
| options | Current parameter can only receive an enumeration value | **Protestant 1**:portrait line\|split,\`json:`gender,options=foo\|bar"\` <br/>**prototype 2**:array style,\`json:"gender,[foo,bar]"\` |
| default | Current Argument Default | \`json:"gender,default=male"\` |
| range | The valid range of the current parameter value, only valid for the value. Details of the writing rule are given below | \`json:"age,range=[0,120]"\` |
| env | Current parameters are taken from environmental variables | \`json:"mode,env=MODE"\` |
| Receive rules | Note | Sample |
| ------------- | --------------------------------------------------------------------------------------------------------------------- |---------------------------------|
| optional | The current field is an optional parameter, allowing zero value (zero value) | \`json:"foo,optional"\` |
| options | Current parameter can only receive an enumeration value | **Protestant 1**:portrait line\ |split,\`json:`gender,options=foo\|bar"\` <br/>**prototype 2**:array style,\`json:"gender,[foo,bar]"\` |
| default | Current Argument Default | \`json:"gender,default=male"\` |
| range | The valid range of the current parameter value, only valid for the value. Details of the writing rule are given below | \`json:"age,range=[0:120]"\` |
| env | Current parameters are taken from environmental variables | \`json:"mode,env=MODE"\` |

::note range expressed value rule
1. Left close interval:(min:max], meaning that min is less than or equal to max, when min is default, min represents value 0, max is unlimited when max is default, min and max are not allowed to default at the same time
Expand Down

0 comments on commit 6ab2d2e

Please sign in to comment.