From 33c60bcd2d3c41a1eeeb92f5c878069b0364da75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 24 Jan 2025 15:05:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84validator=E6=9E=9A=E4=B8=BE?= =?UTF-8?q?=E5=80=BC=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_type.go | 61 ++++++++++-- validator.go | 275 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 282 insertions(+), 54 deletions(-) diff --git a/data_type.go b/data_type.go index 6a89c01..2c5d428 100644 --- a/data_type.go +++ b/data_type.go @@ -197,12 +197,61 @@ func getDataTypeDesc(value DataType, description string) DataTypeDesc { var ( // DataTypeBaseNumber 基础的int类型 - DataTypeBaseNumber = []DataType{DataTypeInt, DataTypeUint, DataTypeFloat, DataTypeIntPtr, DataTypeUintPtr, DataTypeFloatPtr} - DataTypeBaseInt = []DataType{DataTypeInt, DataTypeIntPtr} - DataTypeBaseUint = []DataType{DataTypeUint, DataTypeUintPtr} - DataTypeBaseFloat = []DataType{DataTypeFloat, DataTypeFloatPtr} - DataTypeBaseString = []DataType{DataTypeString, DataTypeStringPtr} - DataTypeBaseBool = []DataType{DataTypeBool, DataTypeBoolPtr} + DataTypeBaseNumber = []DataType{DataTypeInt, DataTypeUint, DataTypeFloat, DataTypeIntPtr, DataTypeUintPtr, DataTypeFloatPtr} + DataTypeBaseInt = []DataType{DataTypeInt, DataTypeIntPtr} + DataTypeBaseUint = []DataType{DataTypeUint, DataTypeUintPtr} + DataTypeBaseFloat = []DataType{DataTypeFloat, DataTypeFloatPtr} + DataTypeBaseString = []DataType{DataTypeString, DataTypeStringPtr} + DataTypeBaseBool = []DataType{DataTypeBool, DataTypeBoolPtr} + DataTypeSliceMarshal = []DataType{ + DataTypeSliceAnyWithMarshal, + DataTypeSliceIntWithMarshal, + DataTypeSliceUintWithMarshal, + DataTypeSliceFloatWithMarshal, + DataTypeSliceBoolWithMarshal, + DataTypeSliceMapAnyAnyWithMarshal, + DataTypeSliceMapStringAnyWithMarshal, + DataTypeSliceAnyWithMarshal, + DataTypeSliceSliceWithMarshal, + } + DataTypeSliceSplit = []DataType{ + DataTypeSliceIntWithChar, + DataTypeSliceUintWithChar, + DataTypeSliceFloatWithChar, + DataTypeSliceBoolWithChar, + DataTypeSliceStringWithChar, + } + DataTypeSlice = []DataType{ + DataTypeSliceString, + DataTypeSliceAny, + DataTypeSliceBool, + DataTypeSliceMapStringAny, + DataTypeSliceInt, + DataTypeSliceUint, + DataTypeSliceFloat, + DataTypeSliceMapAnyAny, + DataTypeSliceSlice, + } + DataTypeMap = []DataType{ + DataTypeMapStrAny, + DataTypeMapAnyAny, + DataTypeMapStrBool, + DataTypeMapStrInt, + DataTypeMapStrFloat, + DataTypeMapStrUint, + DataTypeMapStrSlice, + DataTypeMapStrStr, + } + DataTypeMapMarshal = []DataType{ + DataTypeMapStrAnyWithMarshal, + DataTypeMapAnyAnyWithMarshal, + DataTypeMapStrBoolWithMarshal, + DataTypeMapStrIntWithMarshal, + DataTypeMapStrFloatWithMarshal, + DataTypeMapStrUintWithMarshal, + DataTypeMapStrSliceWithMarshal, + DataTypeMapStrStrWithMarshal, + } ) func getMergeDataTypeList(dataTypeList ...[]DataType) []DataType { diff --git a/validator.go b/validator.go index 1659271..a067bd4 100644 --- a/validator.go +++ b/validator.go @@ -62,22 +62,22 @@ var ValidatorRuleSupportDataTypeTable = map[ValidatorRule]ValidatorRuleConfig{ ValidatorRuleEqcsfield: { ValidatorRule: ValidatorRuleEqcsfield, Description: "跨结构体字段相等", - SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool), + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), }, ValidatorRuleEqfield: { ValidatorRule: ValidatorRuleEqfield, Description: "同结构体字段相等", - SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool), + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), }, ValidatorRuleFieldcontains: { ValidatorRule: ValidatorRuleFieldcontains, Description: "检查指定的字段值是否存在于字段中", - SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), }, ValidatorRuleFieldexcludes: { ValidatorRule: ValidatorRuleFieldexcludes, Description: "检查指定的字段值是否不存在于字段中", - SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), }, ValidatorRuleGtcsfield: { ValidatorRule: ValidatorRuleGtcsfield, @@ -122,22 +122,22 @@ var ValidatorRuleSupportDataTypeTable = map[ValidatorRule]ValidatorRuleConfig{ ValidatorRuleNecsfield: { ValidatorRule: ValidatorRuleNecsfield, Description: "不等于(跨结构体)", - SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool), + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), }, ValidatorRuleNefield: { ValidatorRule: ValidatorRuleNefield, Description: "不等于(同结构体)", - SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool), + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), }, ValidateRuleEq: { ValidatorRule: ValidateRuleEq, Description: "等于(严格校验)", - SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool), + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), }, ValidateRuleEqIgnoreCase: { ValidatorRule: ValidateRuleEqIgnoreCase, Description: "等于(忽略大小写)", - SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool), + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), }, ValidateRuleGt: { ValidatorRule: ValidateRuleGt, @@ -162,41 +162,216 @@ var ValidatorRuleSupportDataTypeTable = map[ValidatorRule]ValidatorRuleConfig{ ValidateRuleNe: { ValidatorRule: ValidateRuleNe, Description: "不等于(严格判断)", - SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool), + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), }, ValidateRuleNeIgnoreCase: { ValidatorRule: ValidateRuleNeIgnoreCase, Description: "不等于(忽略大小写)", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), + }, + ValidatorRuleCommonDir: { + ValidatorRule: ValidatorRuleCommonDir, + Description: "文件夹存在", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), + }, + ValidatorRuleCommonDirPath: { + ValidatorRule: ValidatorRuleCommonDirPath, + Description: "文件夹路径存在", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), + }, + ValidatorRuleCommonFile: { + ValidatorRule: ValidatorRuleCommonFile, + Description: "文件存在", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), + }, + ValidatorRuleCommonFilepath: { + ValidatorRule: ValidatorRuleCommonFilepath, + Description: "文件路径存在", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), + }, + ValidatorRuleCommonImage: { + ValidatorRule: ValidatorRuleCommonImage, + Description: "是否图像资源", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal), + }, + ValidatorRuleCommonIsDefault: { + ValidatorRule: ValidatorRuleCommonIsDefault, + Description: "是否对应类型默认值", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonLen: { + ValidatorRule: ValidatorRuleCommonLen, + Description: "数据长度", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString, DataTypeSliceMarshal, DataTypeSliceSplit, DataTypeMapMarshal, DataTypeSlice, DataTypeMap), // 所有类型均支持 + }, + ValidatorRuleCommonMax: { + ValidatorRule: ValidatorRuleCommonMax, + Description: "最大值", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber), + }, + ValidatorRuleCommonMin: { + ValidatorRule: ValidatorRuleCommonMin, + Description: "最小值", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber), + }, + ValidatorRuleCommonOneOf: { + ValidatorRule: ValidatorRuleCommonOneOf, + Description: "枚举值", SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber, DataTypeBaseString, DataTypeBaseBool), }, + ValidatorRuleCommonRequired: { + ValidatorRule: ValidatorRuleCommonRequired, + Description: "必传校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonRequiredIf: { + ValidatorRule: ValidatorRuleCommonRequiredIf, + Description: "当指定字段等于给定值时, 必传校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonRequiredUnless: { + ValidatorRule: ValidatorRuleCommonRequiredUnless, + Description: "当指定字段不等于给定值时, 必传校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonRequiredWith: { + ValidatorRule: ValidatorRuleCommonRequiredWith, + Description: "当任意一个指定字段不为零值时, 必传校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonRequiredWithAll: { + ValidatorRule: ValidatorRuleCommonRequiredWithAll, + Description: "当全部指定字段不为零值时, 必传校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonRequiredWithout: { + ValidatorRule: ValidatorRuleCommonRequiredWithout, + Description: "当任意一个字段为空时, 必传校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonRequiredWithoutAll: { + ValidatorRule: ValidatorRuleCommonRequiredWithoutAll, + Description: "当全部字段为空时, 必传校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonExcludedIf: { + ValidatorRule: ValidatorRuleCommonExcludedIf, + Description: "当指定字段等于给定值时,排除校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonExcludedUnless: { + ValidatorRule: ValidatorRuleCommonExcludedUnless, + Description: "当指定字段等于给定值时,排除校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonExcludedWith: { + ValidatorRule: ValidatorRuleCommonExcludedWith, + Description: "当全部指定字段不为零值时,排除校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonExcludedWithAll: { + ValidatorRule: ValidatorRuleCommonExcludedWithAll, + Description: "当全部指定字段不为零值时,排除校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonExcludedWithout: { + ValidatorRule: ValidatorRuleCommonExcludedWithout, + Description: "当任意一个指定字段不存在时,排除校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonExcludedWithoutAll: { + ValidatorRule: ValidatorRuleCommonExcludedWithoutAll, + Description: "当全部指定字段不存在时,排除校验", + SupportDataTypeList: nil, // 所有类型均支持 + }, + ValidatorRuleCommonUnique: { + ValidatorRule: ValidatorRuleCommonUnique, + Description: "是否唯一, 用于切片验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeSlice), // 所有类型均支持 + }, + ValidatorRuleFormatterCron: { + ValidatorRule: ValidatorRuleFormatterCron, + Description: "cron表达式验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + }, + ValidatorRuleFormatterEmail: { + ValidatorRule: ValidatorRuleFormatterEmail, + Description: "邮箱地址验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + }, + ValidatorRuleFormatterJson: { + ValidatorRule: ValidatorRuleFormatterJson, + Description: "json格式验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + }, + ValidatorRuleFormatterJwt: { + ValidatorRule: ValidatorRuleFormatterJson, + Description: "JWT(JSON Web Token)验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + }, + ValidatorRuleFormatterLatitude: { + ValidatorRule: ValidatorRuleFormatterLatitude, + Description: "纬度验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber), + }, + ValidatorRuleFormatterLongitude: { + ValidatorRule: ValidatorRuleFormatterLongitude, + Description: "经度验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseNumber), + }, + ValidatorRuleFormatterTimezone: { + ValidatorRule: ValidatorRuleFormatterLongitude, + Description: "时区验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + }, + ValidatorRuleFormatterUrl: { + ValidatorRule: ValidatorRuleFormatterUrl, + Description: "url验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + }, + ValidatorRuleFormatterUri: { + ValidatorRule: ValidatorRuleFormatterUrl, + Description: "uri验证", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + }, + ValidatorRuleFormatterLowercase: { + ValidatorRule: ValidatorRuleFormatterLowercase, + Description: "仅包含小写字符", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + }, + ValidatorRuleFormatterUppercase: { + ValidatorRule: ValidatorRuleFormatterUppercase, + Description: "仅包含大写字符", + SupportDataTypeList: getMergeDataTypeList(DataTypeBaseString), + }, } var ( // ValidatorRuleEqcsfield .....Fields .............. - ValidatorRuleEqcsfield ValidatorRule = "eqcsfield" // 跨结构体字段相等 - ValidatorRuleEqfield ValidatorRule = "eqfield" // 同结构体字段相等 - ValidatorRuleFieldcontains ValidatorRule = "fieldcontains" // 检查指定的字段值是否存在于字段中 - ValidatorRuleFieldexcludes ValidatorRule = "fieldexcludes" // 检查指定的字段值是否存在于字段中 - ValidatorRuleGtcsfield ValidatorRule = "gtcsfield" // 大于(跨结构体) - ValidatorRuleGtecsfield ValidatorRule = "gtecsfield" // 大于等于(跨结构体) - ValidatorRuleGtfield ValidatorRule = "gtfield" // 大于(同结构体) - ValidatorRuleGtefield ValidatorRule = "gtefield" // 大于等于(同结构体) - ValidatorRuleLtcsfield ValidatorRule = "ltcsfield" // 小于(跨结构体) - ValidatorRuleLtecsfield ValidatorRule = "ltecsfield" // 小于等于(跨结构体) - ValidatorRuleLtfield ValidatorRule = "ltfield" // 小于(同结构体) - ValidatorRuleLtefield ValidatorRule = "ltefield" // 小于等于(同结构体) - ValidatorRuleNecsfield ValidatorRule = "necsfield" // 不等于(跨结构体) - ValidatorRuleNefield ValidatorRule = "nefield" // 不等于(同结构体) + ValidatorRuleEqcsfield ValidatorRule = "eqcsfield" // 跨结构体字段相等 eqcsfield={{struct.field}} + ValidatorRuleEqfield ValidatorRule = "eqfield" // 同结构体字段相等 eqfield={{struct.field}} + ValidatorRuleFieldcontains ValidatorRule = "fieldcontains" // 检查指定的字段值是否存在于字段中 fieldcontains={{struct.field}} + ValidatorRuleFieldexcludes ValidatorRule = "fieldexcludes" // 检查指定的字段值是否存在于字段中 fieldexcludes={{struct.field}} + ValidatorRuleGtcsfield ValidatorRule = "gtcsfield" // 大于(跨结构体) gtcsfield={{struct.field}} + ValidatorRuleGtecsfield ValidatorRule = "gtecsfield" // 大于等于(跨结构体) gtecsfield={{struct.field}} + ValidatorRuleGtfield ValidatorRule = "gtfield" // 大于(同结构体) gtfield={{struct.field}} + ValidatorRuleGtefield ValidatorRule = "gtefield" // 大于等于(同结构体) gtefield={{struct.field}} + ValidatorRuleLtcsfield ValidatorRule = "ltcsfield" // 小于(跨结构体) ltcsfield={{struct.field}} + ValidatorRuleLtecsfield ValidatorRule = "ltecsfield" // 小于等于(跨结构体) ltecsfield={{struct.field}} + ValidatorRuleLtfield ValidatorRule = "ltfield" // 小于(同结构体) ltfield={{struct.field}} + ValidatorRuleLtefield ValidatorRule = "ltefield" // 小于等于(同结构体) ltefield={{struct.field}} + ValidatorRuleNecsfield ValidatorRule = "necsfield" // 不等于(跨结构体) necsfield={{struct.field}} + ValidatorRuleNefield ValidatorRule = "nefield" // 不等于(同结构体) nefield={{struct.field}} // ValidateRuleEq Comparisons .................... - ValidateRuleEq ValidatorRule = "eq" // 相等(严格判断) - ValidateRuleEqIgnoreCase ValidatorRule = "eq_ignore_case" // 相等(忽略大小写) - ValidateRuleGt ValidatorRule = "gt" // 大于 - ValidateRuleGte ValidatorRule = "gte" // 大于等于 - ValidateRuleLt ValidatorRule = "lt" // 小于 - ValidateRuleLte ValidatorRule = "lte" // 小于等于 - ValidateRuleNe ValidatorRule = "ne" // 不相等(严格判断) - ValidateRuleNeIgnoreCase ValidatorRule = "ne_ignore_case" // 不相等(忽略大小写) + ValidateRuleEq ValidatorRule = "eq" // 相等(严格判断) eq={{any_value}} + ValidateRuleEqIgnoreCase ValidatorRule = "eq_ignore_case" // 相等(忽略大小写) eq_ignore_case={{any_value}} + ValidateRuleGt ValidatorRule = "gt" // 大于 gt={{number_value}} + ValidateRuleGte ValidatorRule = "gte" // 大于等于 gte={{number_value}} + ValidateRuleLt ValidatorRule = "lt" // 小于 lt={{number_value}} + ValidateRuleLte ValidatorRule = "lte" // 小于等于 lte={{number_value}} + ValidateRuleNe ValidatorRule = "ne" // 不相等(严格判断) ne={{any_value}} + ValidateRuleNeIgnoreCase ValidatorRule = "ne_ignore_case" // 不相等(忽略大小写) ne_ignore_case={{any_value}} // ValidatorRuleCommonDir ............others ValidatorRuleCommonDir ValidatorRule = "dir" // 文件夹存在 @@ -205,24 +380,24 @@ var ( ValidatorRuleCommonFilepath ValidatorRule = "filepath" // 文件路径 ValidatorRuleCommonImage ValidatorRule = "image" // 图像 ValidatorRuleCommonIsDefault ValidatorRule = "isdefault" // 是否默认值 - ValidatorRuleCommonLen ValidatorRule = "len" // 长度 - ValidatorRuleCommonMax ValidatorRule = "max" // 最大值 - ValidatorRuleCommonMin ValidatorRule = "min" // 最小值 - ValidatorRuleCommonOneOf ValidatorRule = "oneof" // 枚举值, 多个空格分隔 + ValidatorRuleCommonLen ValidatorRule = "len" // 长度 len={{uint_value}} + ValidatorRuleCommonMax ValidatorRule = "max" // 最大值 max={{int_value}} + ValidatorRuleCommonMin ValidatorRule = "min" // 最小值 min={{int_value}} + ValidatorRuleCommonOneOf ValidatorRule = "oneof" // 枚举值, 多个空格分隔 oneof={{enum1}} {{enum2}} {{enum....}} ValidatorRuleCommonRequired ValidatorRule = "required" // 必传 - ValidatorRuleCommonRequiredIf ValidatorRule = "required_if" // - ValidatorRuleCommonRequiredUnless ValidatorRule = "required_unless" // - ValidatorRuleCommonRequiredWith ValidatorRule = "required_with" // - ValidatorRuleCommonRequiredWithAll ValidatorRule = "required_with_all" // - ValidatorRuleCommonRequiredWithout ValidatorRule = "required_without" // - ValidatorRuleCommonRequiredWithoutAll ValidatorRule = "required_without_all" // - ValidatorRuleCommonExcludedIf ValidatorRule = "excluded_if" // - ValidatorRuleCommonExcludedUnless ValidatorRule = "excluded_unless" // - ValidatorRuleCommonExcludedWith ValidatorRule = "excluded_with" // - ValidatorRuleCommonExcludedWithAll ValidatorRule = "excluded_with_all" // - ValidatorRuleCommonExcludedWithout ValidatorRule = "excluded_without" // - ValidatorRuleCommonExcludedWithoutAll ValidatorRule = "excluded_without_all" // - ValidatorRuleCommonUnique ValidatorRule = "unique" // + ValidatorRuleCommonRequiredIf ValidatorRule = "required_if" // 当指定字段等于给定值时,校验必传 required_if={{check_field}} {{check_field_value}} {{check_field...}} {{check_field_value...}} + ValidatorRuleCommonRequiredUnless ValidatorRule = "required_unless" // 当指定字段不等于给定值时,校验必传 required_if={{check_field}} {{check_field_value}} {{check_field...}} {{check_field_value...}} + ValidatorRuleCommonRequiredWith ValidatorRule = "required_with" // 当任意一个指定字段不为零值时, 校验必传 required_with={{Field1}} {{Field2}} {{Field...}} + ValidatorRuleCommonRequiredWithAll ValidatorRule = "required_with_all" // 当全部指定字段不为零值时, 校验必传 required_with={{Field1}} {{Field2}} {{Field...}} + ValidatorRuleCommonRequiredWithout ValidatorRule = "required_without" // 任意一个字段为空时,必传校验 required_without={{Field1}} {{Field2}} {{Field...}} + ValidatorRuleCommonRequiredWithoutAll ValidatorRule = "required_without_all" // 全部字段为空时,必传校验 required_without_all={{Field1}} {{Field2}} {{Field...}} + ValidatorRuleCommonExcludedIf ValidatorRule = "excluded_if" // 当指定字段等于给定值时,排除校验 excluded_if={{check_field}} {{check_field_value}} {{check_field...}} {{check_field_value...}} + ValidatorRuleCommonExcludedUnless ValidatorRule = "excluded_unless" // 当指定字段不等于给定值时,排除校验 excluded_if={{check_field}} {{check_field_value}} {{check_field...}} {{check_field_value...}} + ValidatorRuleCommonExcludedWith ValidatorRule = "excluded_with" // 当任意一个指定字段不为零值时,排除校验 excluded_with={{Field1}} {{Field2}} {{Field...}} + ValidatorRuleCommonExcludedWithAll ValidatorRule = "excluded_with_all" // 当全部指定字段不为零值时,排除校验 excluded_with_all={{Field1}} {{Field2}} {{Field...}} + ValidatorRuleCommonExcludedWithout ValidatorRule = "excluded_without" // 当任意一个指定字段不存在时,排除校验 excluded_without={{Field1}} {{Field2}} {{Field...}} + ValidatorRuleCommonExcludedWithoutAll ValidatorRule = "excluded_without_all" // 当q廍指定字段不存在时,排除校验 excluded_without-all={{Field1}} {{Field2}} {{Field...}} + ValidatorRuleCommonUnique ValidatorRule = "unique" // 数据唯一校验 // ValidatorRuleFormatterCron ............. formatter ValidatorRuleFormatterCron ValidatorRule = "cron" // cron表达式 @@ -232,4 +407,8 @@ var ( ValidatorRuleFormatterLatitude ValidatorRule = "latitude" // 纬度 ValidatorRuleFormatterLongitude ValidatorRule = "longitude" // 经度 ValidatorRuleFormatterTimezone ValidatorRule = "timezone" // 时区 + ValidatorRuleFormatterUrl ValidatorRule = "url" // url + ValidatorRuleFormatterUri ValidatorRule = "uri" // uri + ValidatorRuleFormatterLowercase ValidatorRule = "lowercase" // 仅包含小写字符 + ValidatorRuleFormatterUppercase ValidatorRule = "uppercase" // 仅包含大写字符 )