增加部分数据验证转化逻辑

This commit is contained in:
2024-04-29 17:29:46 +08:00
parent 7454036bf5
commit 6f5aad9607
6 changed files with 444 additions and 122 deletions

View File

@ -15,6 +15,7 @@ package define
type FieldRule struct {
Path string `json:"path"` // 字段路径
Type string `json:"type"` // 数据类型, 具体枚举值参见 git.zhangdeman.cn/zhangdeman/consts
DisableRewrite bool `json:"disable_rewrite"` // 验证完相关数据类型之后, 不要重新给字段赋值
DefaultValue string `json:"default_value"` // 默认值, 统一以字符串传入, 会转为最终设置的类型
IsRequired bool `json:"is_required"` // 是否必传
AllowEmpty bool `json:"allow_empty"` // 必传时空字符串是否合法
@ -30,8 +31,8 @@ type FieldRule struct {
//
// Date : 10:58 2024/4/29
type RequiredCondition struct {
DependOnField string `json:"depend_on_field"` // 依赖数据园中的那一个字段
DependOnFieldStatus string `json:"depend_on_field_status"` // 依赖数据状态 : NOT_FOUND / IS_NIL / IS_ZERO / IS_EMPTY / IS_FALSE
DependOnField string `json:"depend_on_field"` // 依赖数据园中的那一个字段
DependOnFieldStatus []string `json:"depend_on_field_status"` // 依赖数据状态 : NOT_FOUND / IS_NIL / IS_ZERO / IS_EMPTY / IS_FALSE
}
// ValueLimit 取值的限制
@ -40,11 +41,11 @@ type RequiredCondition struct {
//
// Date : 11:15 2024/4/29
type ValueLimit struct {
String *StringValueLimit `json:"string"` // 字符串值的限制
Int *IntValueLimit `json:"int"` // int数据验证
Float *FloatValueLimit `json:"float"` // 浮点数据
Slice *SliceValueLimit `json:"slice"` // 数组
Map *MapValueLimit `json:"map"` // map验证
EnumList []string `json:"enum_list"` // 枚举值列表, 仅对 int / float / string 生效
Min *float64 `json:"min"` // 最小值(包含), 对于 int/float, 此值为最小取值, 对于int/map/slice辞职问最小长度
Max *float64 `json:"max"` // 最大值(不包含), 对于 int/float, 此值为最大取值, 对于int/map/slice辞职问最大长度
String *StringValueLimit `json:"string"` // 字符串值的限制
Map *MapValueLimit `json:"map"` // map验证
}
// StringValueLimit 字符串类型值的限制
@ -53,43 +54,8 @@ type ValueLimit struct {
//
// Date : 11:16 2024/4/29
type StringValueLimit struct {
MinLength int64 `json:"min_length"` // 最小长度(包含)
MaxLength int64 `json:"max_length"` // 最大长度(不包含)
AutoTrimSpace bool `json:"auto_trim_space"` // 自动去除前后空格
IncludeSubStrList []string `json:"include_sub_str_list"` // 必须包含指定的子串
EnumList []string `json:"enum_list"` // 枚举值列表
}
// IntValueLimit ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:22 2024/4/29
type IntValueLimit struct {
Min *int64 `json:"min"` // 最小值(包含)
Max *int64 `json:"max"` // 最大值(不包含)
EnumList []int64 `json:"enum_list"` // 枚举值列表
}
// FloatValueLimit ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:22 2024/4/29
type FloatValueLimit struct {
Min *float64 `json:"min"` // 最小值(包含)
Max *float64 `json:"max"` // 最大值(不包含)
EnumList []float64 `json:"enum_list"` // 枚举值列表
}
// SliceValueLimit 数组限制
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 11:23 2024/4/29
type SliceValueLimit struct {
MinLength int64 `json:"min_length"` // 最小长度(包含)
MaxLength int64 `json:"max_length"` // 最大长度(不包含)
}
// MapValueLimit map数据的限制
@ -98,7 +64,5 @@ type SliceValueLimit struct {
//
// Date : 11:23 2024/4/29
type MapValueLimit struct {
MinLength int64 `json:"min_length"` // 最小长度(包含)
MaxLength int64 `json:"max_length"` // 最大长度(不包含)
IncludeFieldList []string `json:"include_field_list"` // 必须存在的字段列表
}