validator
validator copied to clipboard
Using required_with tag for a slice field, but need it's length greater than 0 if it is not nil, how write tag?
Below is my request struct.
type PostLicenseReq struct {
DroneModel string
DroneSns []string `validate:"required_with=DroneModel"`
}
I want the DroneSns length greater than 0 when it is not nil. How to write the tag?
I found write like below but doesn't work, because it must require the DroneSns isn't nil while DroneSns can be nil.
type PostLicenseReq struct {
DroneModel string
DroneSns []string `validate:"required_with=DroneModel,gt=0"`
}
Any one can help me, thanks in advance.