validator
validator copied to clipboard
Validating custom map type
- [x ] I have looked at the documentation here first?
- x[ ] I have looked at the examples provided that may showcase my question here?
Package version eg. v9, v10:
v10
Issue, Question or Enhancement:
Validation on a type that it's a map (not a struct)
Code sample, to showcase or reproduce:
So I have the following type
type MyMap map[uuid.UUID]float64
and I want to validate that map values are >=0 when I am binding from the json string to the go type:
myMap := MyMap{}
if err := c.ShouldBindJSON(&myMap); err != nil {
c.JSON(GenerateResponseError(err))
return
}
I tried it by registering a struct validator
validate.RegisterStructValidation(myMapValidator, MyMap{})
but it does not work because MyMap it's not a struct. How can I achieve that?