how to validate struct in struct?
YellowWinterSun opened this issue · 5 comments
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"},
}
I have the same question.
I have the same question too.
same question
same question
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