constants

package
v0.19.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: Apache-2.0, Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RuleLen = "len" // 长度等于
	RuleMin = "min" // 最小值/长度
	RuleMax = "max" // 最大值/长度
	RuleEq  = "eq"  // 等于
	RuleNe  = "ne"  // 不等于
	RuleGT  = "gt"  // 大于
	RuleGTE = "gte" // 大于等于
	RuleLT  = "lt"  // 小于
	RuleLTE = "lte" // 小于等于

	RuleSymbolEqual              = "="  // 符号:等于
	RuleSymbolNotEqual           = "!=" // 符号:不等于
	RuleSymbolGreaterThan        = ">"  // 符号:大于
	RuleSymbolGreaterThanOrEqual = ">=" // 符号:大于等于
	RuleSymbolLessThan           = "<"  // 符号:小于
	RuleSymbolLessThanOrEqual    = "<=" // 符号:小于等于

	RuleAfter    = "after"     // 时间晚于
	RuleBefore   = "before"    // 时间早于
	RuleRange    = "range"     // 范围校验
	RuleRegex    = "regex"     // 正则匹配
	RuleNotEmpty = "not_empty" // 非空
)
View Source
const (
	RuleOneOf    = "oneof"    // 枚举值(精确匹配)
	RuleOneOfCI  = "oneofci"  // 枚举值(忽略大小写)
	RuleNoneOf   = "noneof"   // 排除值(精确匹配)
	RuleNoneOfCI = "noneofci" // 排除值(忽略大小写)

	RuleRequiredIf         = "required_if"          // 条件必填:指定字段等于目标值时必填
	RuleRequiredUnless     = "required_unless"      // 条件必填:指定字段不等于目标值时必填
	RuleRequiredWith       = "required_with"        // 条件必填:任一指定字段非空时必填
	RuleRequiredWithAll    = "required_with_all"    // 条件必填:所有指定字段非空时必填
	RuleRequiredWithout    = "required_without"     // 条件必填:任一指定字段为空时必填
	RuleRequiredWithoutAll = "required_without_all" // 条件必填:所有指定字段为空时必填

	RuleExcludedIf         = "excluded_if"          // 条件排除:指定字段等于目标值时排除
	RuleExcludedUnless     = "excluded_unless"      // 条件排除:指定字段不等于目标值时排除
	RuleExcludedWith       = "excluded_with"        // 条件排除:任一指定字段非空时排除
	RuleExcludedWithAll    = "excluded_with_all"    // 条件排除:所有指定字段非空时排除
	RuleExcludedWithout    = "excluded_without"     // 条件排除:任一指定字段为空时排除
	RuleExcludedWithoutAll = "excluded_without_all" // 条件排除:所有指定字段为空时排除
)
View Source
const (
	RuleEmpty = "" // 空规则

	RuleRequired  = "required"  // 必填
	RuleIsDefault = "isdefault" // 默认值

	RuleOmitEmpty = "omitempty" // 空值省略
	RuleOmitZero  = "omitzero"  // 零值省略
	RuleOmitNil   = "omitnil"   // nil 省略

	RuleDive          = "dive"          // 递归进入切片/映射
	RuleKeys          = "keys"          // 映射键规则开始
	RuleEndKeys       = "endkeys"       // 映射键规则结束
	RuleStructOnly    = "structonly"    // 仅校验结构体本身
	RuleNoStructLevel = "nostructlevel" // 跳过结构体级校验
)
View Source
const (
	RuleEqField     = "eqfield"     // 等于指定字段
	RuleNeField     = "nefield"     // 不等于指定字段
	RuleGTField     = "gtfield"     // 大于指定字段
	RuleGTEField    = "gtefield"    // 大于等于指定字段
	RuleLTField     = "ltfield"     // 小于指定字段
	RuleLTEField    = "ltefield"    // 小于等于指定字段
	RuleAfterField  = "afterfield"  // 时间晚于指定字段
	RuleBeforeField = "beforefield" // 时间早于指定字段

	RuleFieldLen = "fieldlen" // 与指定字段长度比较,参数格式: FieldName 或 op:FieldName(op 可选 eq/ne/gt/gte/lt/lte,默认 eq)

	RuleEqCSField  = "eqcsfield"  // 等于跨结构体字段
	RuleNeCSField  = "necsfield"  // 不等于跨结构体字段
	RuleGTCSField  = "gtcsfield"  // 大于跨结构体字段
	RuleGTECSField = "gtecsfield" // 大于等于跨结构体字段
	RuleLTCSField  = "ltcsfield"  // 小于跨结构体字段
	RuleLTECSField = "ltecsfield" // 小于等于跨结构体字段

	RuleFieldContains = "fieldcontains" // 字段包含指定字段值
	RuleFieldExcludes = "fieldexcludes" // 字段不包含指定字段值
)
View Source
const (
	RuleEmail = "email" // 邮箱地址
	RuleE164  = "e164"  // E.164 电话号码

	RuleIP     = "ip"      // IP 地址(v4 或 v6)
	RuleIPAddr = "ip_addr" // IP 地址别名
	RuleIPv4   = "ipv4"    // IPv4 地址
	RuleIPv6   = "ipv6"    // IPv6 地址

	RuleCIDR   = "cidr"   // CIDR 表示法
	RuleCIDRv4 = "cidrv4" // IPv4 CIDR
	RuleCIDRv6 = "cidrv6" // IPv6 CIDR

	RuleMAC = "mac" // MAC 地址

	RuleHostname        = "hostname"         // 主机名
	RuleHostnameRFC1123 = "hostname_rfc1123" // RFC1123 主机名
	RuleFQDN            = "fqdn"             // 完全限定域名
	RuleHostnamePort    = "hostname_port"    // 主机名:端口
	RulePort            = "port"             // 端口号

	RuleURL        = "url"         // URL
	RuleURI        = "uri"         // URI
	RuleHTTPURL    = "http_url"    // HTTP URL
	RuleHTTPSURL   = "https_url"   // HTTPS URL
	RuleURLEncoded = "url_encoded" // URL 编码字符串

	RuleHTML        = "html"         // HTML 标签
	RuleHTMLEncoded = "html_encoded" // HTML 编码字符串

	RuleUUID         = "uuid"          // UUID(任意版本)
	RuleUUID3        = "uuid3"         // UUID v3
	RuleUUID4        = "uuid4"         // UUID v4
	RuleUUID5        = "uuid5"         // UUID v5
	RuleUUIDRFC4122  = "uuid_rfc4122"  // RFC4122 UUID
	RuleUUID3RFC4122 = "uuid3_rfc4122" // RFC4122 UUID v3
	RuleUUID4RFC4122 = "uuid4_rfc4122" // RFC4122 UUID v4
	RuleUUID5RFC4122 = "uuid5_rfc4122" // RFC4122 UUID v5

	RuleBase32       = "base32"       // Base32 编码
	RuleBase64       = "base64"       // Base64 编码
	RuleBase64URL    = "base64url"    // Base64URL 编码
	RuleBase64RawURL = "base64rawurl" // Base64RawURL 编码(无填充)

	RuleHexColor = "hexcolor" // 十六进制颜色值
	RuleRGB      = "rgb"      // RGB 颜色
	RuleRGBA     = "rgba"     // RGBA 颜色
	RuleHSL      = "hsl"      // HSL 颜色
	RuleHSLA     = "hsla"     // HSLA 颜色

	RuleSemver  = "semver"   // 语义化版本号
	RuleISBN10  = "isbn10"   // ISBN-10
	RuleISBN13  = "isbn13"   // ISBN-13
	RuleISSN    = "issn"     // ISSN
	RuleBIC     = "bic"      // BIC/SWIFT 代码
	RuleCron    = "cron"     // Cron 表达式
	RuleDataURI = "datauri"  // Data URI
	RuleBCP47   = "bcp47"    // BCP47 语言标签
	RuleEthAddr = "eth_addr" // 以太坊地址
	RuleBtcAddr = "btc_addr" // 比特币地址

	RuleDatetime = "datetime" // 日期时间格式
	RuleTimezone = "timezone" // 时区

	RuleFile     = "file"     // 文件路径
	RuleFilepath = "filepath" // 文件路径(别名)
	RuleDir      = "dir"      // 目录路径
	RuleDirpath  = "dirpath"  // 目录路径(别名)

	RuleMongoDB = "mongodb" // MongoDB ObjectID

	RuleLuhnChecksum    = "luhn_checksum"     // Luhn 校验和
	RuleCreditCard      = "credit_card"       // 信用卡号
	RuleDNSRFC1035Label = "dns_rfc1035_label" // DNS RFC1035 标签
)
View Source
const (
	RuleImage = "image" // 图片(任意支持格式,可用空格分隔参数指定白名单)
	RulePNG   = "png"   // PNG 图片(含 IEND 尾块完整性检查)
	RuleJPG   = "jpg"   // JPEG 图片(RuleJPEG 别名)
	RuleJPEG  = "jpeg"  // JPEG 图片(含 EOI 尾部完整性检查)
	RuleGIF   = "gif"   // GIF 图片(含 0x3B 尾部完整性检查)
	RuleWebP  = "webp"  // WebP 图片
	RuleBMP   = "bmp"   // BMP 图片
	RuleTIFF  = "tiff"  // TIFF 图片
	RuleICO   = "ico"   // ICO 图标
	RuleAVIF  = "avif"  // AVIF 图片
	RuleHEIC  = "heic"  // HEIC/HEIF 图片
	RuleSVG   = "svg"   // SVG 文档
)
View Source
const (
	RuleUnique  = "unique"  // 唯一性
	RuleBoolean = "boolean" // 布尔值
	RuleNumber  = "number"  // 数字
	RuleNumeric = "numeric" // 数值(number 别名)
	RuleInteger = "integer" // 整数(数值字段必须为整数,字符串字段必须为纯整数)
	RuleJSON    = "json"    // JSON 格式

	RuleLatitude  = "latitude"  // 纬度
	RuleLongitude = "longitude" // 经度
)
View Source
const (
	RuleDigits              = "digits"           // 纯数字字符串
	RuleIntOrFloat          = "int_or_float"     // 整数或最多2位小数
	RuleWordChars           = "word_chars"       // 字母数字下划线
	RuleUpperAlpha          = "upper_alpha"      // 纯大写字母
	RuleLowerAlpha          = "lower_alpha"      // 纯小写字母
	RuleStrongPassword      = "strong_password"  // 强密码(8位+大小写+数字+特殊字符)
	RuleHasSpecial          = "has_special"      // 包含特殊字符
	RuleHasDoubleByte       = "has_double_byte"  // 包含双字节字符
	RuleEmptyLine           = "empty_line"       // 空白行
	RuleChinesePhone        = "cn_phone"         // 中国大陆手机号
	RuleChineseIDCard       = "cn_idcard"        // 中国大陆身份证号(15或18位)
	RuleChineseIDCardStrict = "cn_idcard_strict" // 身份证号含校验和验证
)
View Source
const (
	RuleAlpha           = "alpha"           // 纯字母
	RuleAlphaSpace      = "alphaspace"      // 字母+空格
	RuleAlphanum        = "alphanum"        // 字母数字
	RuleAlphanumSpace   = "alphanumspace"   // 字母数字+空格
	RuleAlphaUnicode    = "alphaunicode"    // Unicode 字母
	RuleAlphanumUnicode = "alphanumunicode" // Unicode 字母数字

	RuleASCII       = "ascii"       // ASCII 字符
	RulePrintASCII  = "printascii"  // 可打印 ASCII
	RuleMultibyte   = "multibyte"   // 多字节字符
	RuleHexadecimal = "hexadecimal" // 十六进制字符串

	RuleStartsWith    = "startswith"    // 前缀匹配
	RuleEndsWith      = "endswith"      // 后缀匹配
	RuleStartsNotWith = "startsnotwith" // 前缀不匹配
	RuleEndsNotWith   = "endsnotwith"   // 后缀不匹配

	RuleContains     = "contains"     // 包含子串
	RuleContainsAny  = "containsany"  // 包含任一字符
	RuleContainsRune = "containsrune" // 包含指定 rune

	RuleExcludes     = "excludes"     // 不包含子串
	RuleExcludesAll  = "excludesall"  // 不包含任一字符
	RuleExcludesRune = "excludesrune" // 不包含指定 rune

	RuleLowercase = "lowercase" // 全小写
	RuleUppercase = "uppercase" // 全大写

	RuleEqIgnoreCase = "eq_ignore_case" // 忽略大小写等于
	RuleNeIgnoreCase = "ne_ignore_case" // 忽略大小写不等于
)

Variables

This section is empty.

Functions

func CompareOperatorForRule

func CompareOperatorForRule(name string) string

CompareOperatorForRule 返回规则对应的比较操作符字符串

func IsCrossStructFieldCompareRule

func IsCrossStructFieldCompareRule(name string) bool

IsCrossStructFieldCompareRule 是否为跨结构体字段比较规则

func IsDiveControlRule

func IsDiveControlRule(name string) bool

IsDiveControlRule 是否为递归控制规则

func IsFieldCompareRule

func IsFieldCompareRule(name string) bool

IsFieldCompareRule 是否为跨字段比较规则(含同结构体和跨结构体)

func IsLocalFieldCompareRule

func IsLocalFieldCompareRule(name string) bool

IsLocalFieldCompareRule 是否为同结构体字段比较规则

func IsOmitEmptyRule

func IsOmitEmptyRule(name string) bool

IsOmitEmptyRule 是否为省略空值规则(omitempty/omitzero)

func IsScalarCompareRule

func IsScalarCompareRule(name string) bool

IsScalarCompareRule 是否为标量比较规则(min/max/len/gt/gte/lt/lte)

func IsStructControlRule

func IsStructControlRule(name string) bool

IsStructControlRule 是否为结构体控制规则

func NeedsParamParts

func NeedsParamParts(name string) bool

NeedsParamParts 是否需要将参数按空白拆分为多个部分

func StopsStructDive

func StopsStructDive(name string) bool

StopsStructDive 是否停止结构体递归

Types

type CmpOp

type CmpOp int

CmpOp 整型比较运算符,用于内部快速 switch 分发

const (
	CmpEQ  CmpOp = iota // 等于
	CmpLT               // 小于
	CmpLTE              // 小于等于
	CmpGT               // 大于
	CmpGTE              // 大于等于
	CmpNE               // 不等于
)

func CmpOpForOperator

func CmpOpForOperator(op CompareOperator) CmpOp

CmpOpForOperator 将 CompareOperator 转换为 CmpOp

func CmpOpFromStr

func CmpOpFromStr(op string) CmpOp

CmpOpFromStr 将字符串操作符转换为 CmpOp,未匹配返回 -1

type CompareOperator

type CompareOperator string

CompareOperator 操作符类型

const (
	OpEqual                    CompareOperator = RuleEq
	OpNotEqual                 CompareOperator = RuleNe
	OpGreaterThan              CompareOperator = RuleGT
	OpGreaterThanOrEqual       CompareOperator = RuleGTE
	OpLessThan                 CompareOperator = RuleLT
	OpLessThanOrEqual          CompareOperator = RuleLTE
	OpContains                 CompareOperator = "contains"
	OpNotContains              CompareOperator = "not_contains"
	OpHasPrefix                CompareOperator = "has_prefix"
	OpHasSuffix                CompareOperator = "has_suffix"
	OpRegex                    CompareOperator = RuleRegex
	OpEmpty                    CompareOperator = "empty"
	OpNotEmpty                 CompareOperator = RuleNotEmpty
	OpSymbolEqual              CompareOperator = RuleSymbolEqual
	OpSymbolNotEqual           CompareOperator = RuleSymbolNotEqual
	OpSymbolGreaterThan        CompareOperator = RuleSymbolGreaterThan
	OpSymbolGreaterThanOrEqual CompareOperator = RuleSymbolGreaterThanOrEqual
	OpSymbolLessThan           CompareOperator = RuleSymbolLessThan
	OpSymbolLessThanOrEqual    CompareOperator = RuleSymbolLessThanOrEqual
)

func (CompareOperator) String

func (op CompareOperator) String() string

String 返回操作符字符串表示

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL