ozzo-validation icon indicating copy to clipboard operation
ozzo-validation copied to clipboard

".By()" method not working for Map validation

Open darienmiller88 opened this issue 3 years ago • 0 comments

When attempting to validate a map field using the .By() method, the data (in this case an array) passed to the function no longer exists, even when I pass my map to the .Map() method by reference. How do I fix this?

func validateMap(reminder map[string]interface{}) error {
	fmt.Println("days:", reminder["days"])//This field, an array, is printed with all of its values in tac.
	return validation.Validate(&reminder,
		validation.Map(
			validation.Key("days", validation.By(test)).Optional(),
		),
	)
}

func test(val interface{}) error{
	v, _ := val.([]string)

	fmt.Println("v:", v)//Here however, the array is empty.
	return nil
}

darienmiller88 avatar Nov 26 '21 09:11 darienmiller88