From f175cc4f755c746ce94bd07918eedb9d0d05e9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 29 Apr 2024 12:17:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0field=20rule=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- define/rule.go | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ run.go | 12 ++++++ 2 files changed, 113 insertions(+) create mode 100644 define/rule.go create mode 100644 run.go diff --git a/define/rule.go b/define/rule.go new file mode 100644 index 0000000..2027320 --- /dev/null +++ b/define/rule.go @@ -0,0 +1,101 @@ +// Package define ... +// +// Description : define ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2024-04-29 10:51 +package define + +// FieldRule 字段验证规则 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 10:52 2024/4/29 +type FieldRule struct { + Path string `json:"path"` // 字段路径 + Type string `json:"type"` // 数据类型, 具体枚举值参见 git.zhangdeman.cn/zhangdeman/consts + DefaultValue string `json:"default_value"` // 默认值, 统一以字符串传入, 会转为最终设置的类型 + IsRequired bool `json:"is_required"` // 是否必传 + RequiredConditionGroup [][]RequiredCondition `json:"required_condition_group"` // 满足何种条件,字段必传,不配置则为无差别必传, 组之间是或条件, 满足一组即命中, 组之内为与条件 + ValueLimit *ValueLimit `json:"value_limit"` // 数据值的限制 +} + +// RequiredCondition 定义必传条件 +// +// Author : zhangdeman001@ke.com<张德满> +// +// 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 +} + +// ValueLimit 取值的限制 +// +// Author : go_developer@163.com<白茶清欢> +// +// 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验证 +} + +// StringValueLimit 字符串类型值的限制 +// +// Author : go_developer@163.com<白茶清欢> +// +// 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数据的限制 +// +// Author : go_developer@163.com<白茶清欢> +// +// 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"` // 必须存在的字段列表 +} diff --git a/run.go b/run.go new file mode 100644 index 0000000..867cae4 --- /dev/null +++ b/run.go @@ -0,0 +1,12 @@ +// Package validator ... +// +// Description : validator ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2024-04-29 10:51 +package validator + +func Run() { + +}