【发布时间】:2020-05-28 00:37:02
【问题描述】:
我有一个具有这种结构的复杂对象。
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 来迭代呢?
【问题讨论】:
-
什么是
validator? -
它是实体的 gopkg 验证器... gopkg.in/go-playground/validator.v9
标签: arrays validation go go-playground