I'm trying to use gin framework to validate a slice of struct in order to ensure the slice is unique.
With The following code:
type CreateOrderParam struct {
Items []*CreateItemParam `form:"items" binding:"gt=0,required,unique,dive"`
}
type CreateItemParam struct {
Dress *CreateDressParam `form:"dress" validate:"required"`
}
type CreateDressParam struct {
Id int `form:"id" validate:"gt=0,required"`
}
I use the following JSON to test the code:
{
"items": [
{
"dress": {
"id": 1
}
},
{
"dress": {
"id": 1
}
},
{
"dress": {
"id": 3
}
}
]
}
However,the JSON pass validation.So **I doubt that the unique tag not being used correctly.**My question is:how to use the unique tag to validate the slice of struct?