-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
请求参数如果是bool型,false会被解析为true,只有0才会解析为false #4093
Comments
请给出完整示例代码 |
Please give complete sample code |
// PageReq 分页请求
type PageReq struct {
Page int `json:"page" example:"10" d:"1" v:"min:1#页码最小值不能低于1" dc:"当前页码"`
PerPage int `json:"pageSize" example:"1" d:"10" v:"min:1|max:200#每页数量最小值不能低于1|最大值不能大于200" dc:"每页数量"`
Pagination bool `json:"pagination" d:"true" dc:"是否需要进行分页"`
} 比如这里的是否分页 |
// PageReq paging request |
@Q32611600 我在2.7.0版本中尝试了没有问题,false会被正确解析为false |
@Q32611600 I tried it in version 2.7.0 with no problem, false will be correctly parsed as false |
v2.8.0 |
@Q32611600 看起来是字段的d tag的问题,我加了d tag问题就复现了 |
@Q32611600 It seems to be a problem with the d tag of the field. I added the d tag and the problem reappeared. |
强仔
***@***.***
…------------------ 原始邮件 ------------------
发件人: "gogf/gf" ***@***.***>;
发送时间: 2025年1月5日(星期天) 晚上6:10
***@***.***>;
***@***.******@***.***>;
主题: Re: [gogf/gf] 请求参数如果是bool型,false会被解析为true,只有0才会解析为false (Issue #4093)
@Q32611600 我在2.7.0版本中尝试了没有问题,false会被正确解析为false
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
的确如此,我把缺省值去掉后测试。正如您所说是正确的
强仔
***@***.***
…------------------ 原始邮件 ------------------
发件人: "gogf/gf" ***@***.***>;
发送时间: 2025年1月5日(星期天) 晚上6:14
***@***.***>;
***@***.******@***.***>;
主题: Re: [gogf/gf] 请求参数如果是bool型,false会被解析为true,只有0才会解析为false (Issue #4093)
@Q32611600 看起来是字段的d tag的问题,我加了d tag问题就复现了
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@gqcn 目前mergeDefaultStructValue这个函数看起来有逻辑错误,当用户传值时,如果传的是类型的默认值,并且如果给字段设置了默认值的话(当和类型的默认值不同时),会给这个字段设置默认值 |
@gqcn At present, the mergeDefaultStructValue function seems to have a logical error. When the user passes a value, if the default value of the type is passed, and if a default value is set for the field (when it is different from the default value of the type), this will be given Field settings default value |
@gqcn 我尝试了数字类型和字符串类型添加默认值时,数字类型不会被设置默认值,因为它被解析为json.Number,传0时,会被认为非空的 使用以下参数传递 {
"state": "",
"pagination": false,
"k1":0
} // 对应的结构体
type HelloReq struct {
g.Meta `path:"/hello" tags:"Hello" method:"get" summary:"You first hello api"`
State string `json:"state" d:"default_state"`
Pagination bool `json:"pagination" d:"true"`
K1 int `json:"k1" d:"198"`
} |
Go version
arm64
GoFrame version
ex 2.7
Can this bug be reproduced with the latest release?
Option Yes
What did you do?
{
"state": "",
"pagination": false
} 请求参数中的false会被解析为true,只有0才会false
What did you see happen?
{
"state": "",
"pagination": false
} 请求参数中的false会被解析为true,只有0才会false
What did you expect to see?
{
"state": "",
"pagination": false
} 请求参数中的false会被解析为true,只有0才会false
The text was updated successfully, but these errors were encountered: