Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
darienmiller88 opened this issue Nov 26, 2021 · 0 comments
Open

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

darienmiller88 opened this issue Nov 26, 2021 · 0 comments

Comments

@darienmiller88
Copy link

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant