go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.14k stars 1.29k forks source link

[resolved]Question: validate the member of slice #1153

Closed PetterZhukov closed 7 months ago

PetterZhukov commented 10 months ago

Package version eg. v9, v10:

v9

Issue, Question or Enhancement:

When using the struct method to validate a struct A, one member a is a slice composed of another struct B. How to set the tag of a to call the validate validation of B

Code sample, to showcase or reproduce:

type A struct {
a []B validate:"required"
}
type B struct {
b xxx validate:"required,validateb"
}

How should I modify A.a's tag to call b's validation function validateb

PetterZhukov commented 10 months ago

That's great. I found the “dive” tag in the document, maybe it can achieve the goal