Closed modest0 closed 2 years ago
@modest0 You certainly can do this, by using the dive
tag. Example would be
type Request struct {
PaymentOptions []string `json:"paymentOptions" validate:"required,dive,oneof=visa amex cash voucher'"`
}
See: https://go.dev/play/p/31TZwJBGGjx https://pkg.go.dev/github.com/go-playground/validator/v10#hdr-Dive
Package version eg. v9, v10:
v10
Issue, Question or Enhancement:
Question
Code sample, to showcase or reproduce:
I have a common scenario here where I need to validate if all the values received in a slice of string are contained / exists in a known set of allowed values. I always end up writting a custom validator but I wonder if it's possible achieve the same thing with the built in rules or a new set of rules like a
containsOnly
oranyOf
.