go-ozzo / ozzo-validation

An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
MIT License
3.73k stars 224 forks source link

Each() doesn't validate the keys in a map, just the values. #97

Open tdbs opened 4 years ago

tdbs commented 4 years ago

When using the Each() func to validate a map, it iterates over the values, but not the keys. Keys may be invalid too, so I would like to test both.

JensErat commented 4 years ago

Similar issue for me, I'd love to validate both keys and values of a map[string]string with different rules for keys and values. Achieved so far by building a custom validation rule and validate function. Maybe something similar to the when/else construct:

validation.Each(validation.Required).Keys(is.UUID))

for validating all keys are UUIDs, and the values are required.

-- Jens Erat \jens.erat@daimler.com\, Daimler TSS GmbH
Imprint