validator
validator copied to clipboard
How to get index current validated struct inside custom validation
- [ ] I have looked at the documentation here first?
- [ ] I have looked at the examples provided that may showcase my question here?
Package version eg. v10:
Issue, Question or Enhancement:
This ilustrate my problem:
type Parent struct {
Childs []Child validate:"dive"
}
type Child struct {
JustAField string validate:"customValidation"
}
func customValidation(fl validator.FieldLevel) bool { // here I want to get the index of child // which currently being validated }
errs := validate.Struct(Parent) I cannot find a method to get current index of child inside customValidation,
But if there is an error, somehow the library itself knows the index:
for _, e := range errs { e.Namespace() // Parent.childs[0].just_a_field } does anyone know how to get the index?
thanks
Code sample, to showcase or reproduce:
@init-database Did you ever solve this? Seems related to this other issue: https://github.com/go-playground/validator/issues/802