Ai
1 Star 1 Fork 1

c./goframe框架

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
builtin_required_without.go 1.35 KB
一键复制 编辑 原始数据 按行查看 历史
admin 提交于 2024-11-08 04:16 +08:00 . 2024-11-7
// 版权归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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go_888/goframe.git
git@gitee.com:go_888/goframe.git
go_888
goframe
goframe框架
782a3f7170cf

搜索帮助