代码拉取完成,页面将自动刷新
// 版权归GoFrame作者(https://goframe.org)所有。保留所有权利。
//
// 本源代码形式受MIT许可证条款约束。
// 如果未随本文件一同分发MIT许可证副本,
// 您可以在https://github.com/gogf/gf处获取。
// md5:a9832f33b234e3f3
package builtin
import (
"errors"
"strings"
"gitee.com/go_888/goframe/internal/empty"
gutil "gitee.com/go_888/goframe/util/gutil"
)
// RuleRequiredWithout 实现了 `required-without` 规则:
// 如果给定的任何字段为空,那么这个是必需的。
//
// 格式: required-without:field1,field2,...
// 示例: required-without:id,name
// md5:2e4a4e507f20f3a1
type RuleRequiredWithout struct{}
func init() {
Register(RuleRequiredWithout{})
}
func (r RuleRequiredWithout) Name() string {
return "required-without"
}
func (r RuleRequiredWithout) Message() string {
return "{field}字段不能为空"
}
func (r RuleRequiredWithout) Run(in RunInput) error {
var (
required = false
array = strings.Split(in.RulePattern, ",")
foundValue interface{}
dataMap = in.Data.X取Map()
)
for i := 0; i < len(array); i++ {
_, foundValue = gutil.Map查找并忽略大小写与符号(dataMap, array[i])
if empty.IsEmpty(foundValue) {
required = true
break
}
}
if required && isRequiredEmpty(in.Value.X取值()) {
return errors.New(in.Message)
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。