我有一个具有这种结构的复杂对象。
type People struct {
Objectives []string `validate:"required,ValidateCustom" json:"Objectives"`
}
我需要在枚举中测试列表思考,使用gopkg.in/go-playground/validator.v9
:
//ValidateCustom -- ValidateCustom
func ValidateCustom(field validator.FieldLevel) bool {
switch strings.ToUpper(field.Field().String()) {
case "emumA":
case "enumB":
return true
default:
return false
}
}
这个例子使用了字符串的概念,但是我怎样才能构建到 []string 来迭代呢?