ozzo-validation
ozzo-validation copied to clipboard
".By()" method not working for Map validation
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
}