Skip to content
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

how to validate struct in struct? #120

Open
YellowWinterSun opened this issue Dec 6, 2022 · 5 comments
Open

how to validate struct in struct? #120

YellowWinterSun opened this issue Dec 6, 2022 · 5 comments

Comments

@YellowWinterSun
Copy link

code like this

// QueryPageProjectGrailRequest Request 请求
type QueryPageProjectGrailRequest struct {
PageNo int32 json:"page_no" // 页码
PageSize int32 json:"page_size" // 每页数量
Sort string json:"sort" // 排序,支持多个 such as "col1 desc, col2 asc"
Filter []queryProjectGrailFilter json:"filter" // 筛选(高级查询)
Keywords []string json:"keywords" // 全文检索能力
}

type queryProjectGrailFilter struct {
Field string json:"field"
Condition string json:"condition"
Relation string json:"relation"
Value string json:"value"
}

I don't know how to validator field in filter? such as filter.relation

// relation didn't work
rules := govalidator.MapData{
"page_no": []string{"required", "numeric_between:1,100000"},
"page_size": []string{"required", "numeric_between:1,1000"},
"relation": []string{"between:1,5"},
}

@devhaozi
Copy link

devhaozi commented Feb 6, 2023

I have the same question.

@linxun
Copy link

linxun commented Jul 4, 2023

I have the same question too.

@frank505
Copy link

same question

1 similar comment
@atighineanu
Copy link

same question

@Kirari04
Copy link

There is an example of a nested struct validation but it it might get things wrong if the nested struct has the same keys as the parent: https://github.com/thedevsaddam/govalidator/blob/master/doc/NESTED_STRUCT.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants