builtin

package
v0.0.0-...-782a3f7 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

包 builtin 实现了内置的验证规则。

参考了 Laravel 验证规则: https://laravel.com/docs/master/validation#available-validation-rules md5:855d785bc4982d21

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(rule Rule)

Register 将内置规则注册到管理器中。 md5:491be1bd9cfa9577

Types

type Rule

type Rule interface {
	// Name 返回该规则的内置名称。 md5:a71cebab229252cc
	Name() string

	// Message返回规则的默认错误消息。 md5:0b3669ebda3f3237
	Message() string

	// Run开始运行规则,如果成功则返回nil,否则返回一个错误。 md5:1e3c94009a35745d
	Run(in RunInput) error
}

func GetRule

func GetRule(name string) Rule

GetRule 通过 `name` 获取并返回规则。 md5:a84a676e5ebc496b

type RuleAfter

type RuleAfter struct{}

RuleAfter 实现了`after`规则: 日期时间值应该大于字段`field`的值。

格式:after:field md5:7bbbedf5ca280678

func (RuleAfter) Message

func (r RuleAfter) Message() string

func (RuleAfter) Name

func (r RuleAfter) Name() string

func (RuleAfter) Run

func (r RuleAfter) Run(in RunInput) error

type RuleAfterEqual

type RuleAfterEqual struct{}

RuleAfterEqual 实现了 `after-equal` 规则: 日期时间值应该在字段 `field` 的值之后或等于该值。

格式:after-equal:field md5:b4f07a240c382495

func (RuleAfterEqual) Message

func (r RuleAfterEqual) Message() string

func (RuleAfterEqual) Name

func (r RuleAfterEqual) Name() string

func (RuleAfterEqual) Run

func (r RuleAfterEqual) Run(in RunInput) error

type RuleArray

type RuleArray struct{}

RuleArray 实现了 `array` 规则: 值应为数组类型。

格式:array md5:242ac4bf271dd8e1

func (RuleArray) Message

func (r RuleArray) Message() string

func (RuleArray) Name

func (r RuleArray) Name() string

func (RuleArray) Run

func (r RuleArray) Run(in RunInput) error

type RuleBail

type RuleBail struct{}

RuleBail 实现了 `bail` 规则: 当此字段的验证失败时,停止进行后续验证。

格式:bail md5:be07eaed27ee8cf4

func (RuleBail) Message

func (r RuleBail) Message() string

func (RuleBail) Name

func (r RuleBail) Name() string

func (RuleBail) Run

func (r RuleBail) Run(in RunInput) error

type RuleBankCard

type RuleBankCard struct{}

```go RuleBankCard 实现了 `bank-card` 规则: 银行卡号。

格式:bank-card ```

这段Go代码的注释是描述一个名为RuleBankCard的实现,它与验证银行卡号相关的规则有关。规则的格式是"bank-card"。 md5:c9583cdff892228a

func (RuleBankCard) Message

func (r RuleBankCard) Message() string

func (RuleBankCard) Name

func (r RuleBankCard) Name() string

func (RuleBankCard) Run

func (r RuleBankCard) Run(in RunInput) error

type RuleBefore

type RuleBefore struct{}

RuleBefore 实现了 `before` 规则: 日期时间值应晚于字段 `field` 的值。

格式:before:field md5:17c681cee9b7f9c0

func (RuleBefore) Message

func (r RuleBefore) Message() string

func (RuleBefore) Name

func (r RuleBefore) Name() string

func (RuleBefore) Run

func (r RuleBefore) Run(in RunInput) error

type RuleBeforeEqual

type RuleBeforeEqual struct{}

RuleBeforeEqual 实现了“before-equal”规则: 日期时间值应该大于或等于字段 `field` 的值。

格式:before-equal:field md5:f50af52a18b33834

func (RuleBeforeEqual) Message

func (r RuleBeforeEqual) Message() string

func (RuleBeforeEqual) Name

func (r RuleBeforeEqual) Name() string

func (RuleBeforeEqual) Run

func (r RuleBeforeEqual) Run(in RunInput) error

type RuleBetween

type RuleBetween struct{}

RuleBetween 实现了 `between` 规则: 范围在 :min 和 :max 之间。它支持整数和浮点数。

格式:between:min,max md5:99eb04ab3fef89e8

func (RuleBetween) Message

func (r RuleBetween) Message() string

func (RuleBetween) Name

func (r RuleBetween) Name() string

func (RuleBetween) Run

func (r RuleBetween) Run(in RunInput) error

type RuleBoolean

type RuleBoolean struct{}

RuleBoolean 实现了 `boolean` 规则: Boolean(1, true, on, yes: true | 0, false, off, no, "": false)

格式:boolean md5:b799fb342217ec2b

func (RuleBoolean) Message

func (r RuleBoolean) Message() string

func (RuleBoolean) Name

func (r RuleBoolean) Name() string

func (RuleBoolean) Run

func (r RuleBoolean) Run(in RunInput) error

type RuleCi

type RuleCi struct{}

RuleCi 实现了 `ci` 规则: 为需要值比较的规则(如:相同、不同、属于、不属于等)提供了大小写不敏感的配置。

格式:ci md5:2a5b8056a85341d7

func (RuleCi) Message

func (r RuleCi) Message() string

func (RuleCi) Name

func (r RuleCi) Name() string

func (RuleCi) Run

func (r RuleCi) Run(in RunInput) error

type RuleDate

type RuleDate struct{}

RuleDate 实现了 `date` 规则: 标准日期格式,例如:2006-01-02, 20060102, 2006.01.02。

格式:date md5:91044156fb254923

func (RuleDate) Message

func (r RuleDate) Message() string

func (RuleDate) Name

func (r RuleDate) Name() string

func (RuleDate) Run

func (r RuleDate) Run(in RunInput) error

type RuleDateFormat

type RuleDateFormat struct{}

RuleDateFormat 实现了 `date-format` 规则: 定制日期格式。

格式:date-format:format md5:e25dffe38dd1e8e8

func (RuleDateFormat) Message

func (r RuleDateFormat) Message() string

func (RuleDateFormat) Name

func (r RuleDateFormat) Name() string

func (RuleDateFormat) Run

func (r RuleDateFormat) Run(in RunInput) error

type RuleDatetime

type RuleDatetime struct{}

RuleDatetime 实现了 `datetime` 规则: 标准日期时间格式,例如:2006-01-02 12:00:00。

格式:datetime md5:cd1da4eb292e6ea1

func (RuleDatetime) Message

func (r RuleDatetime) Message() string

func (RuleDatetime) Name

func (r RuleDatetime) Name() string

func (RuleDatetime) Run

func (r RuleDatetime) Run(in RunInput) error

type RuleDifferent

type RuleDifferent struct{}

RuleDifferent 实现了 `different` 规则: 值应该与字段的值不同。

格式:different:field md5:4b333f141ec615fb

func (RuleDifferent) Message

func (r RuleDifferent) Message() string

func (RuleDifferent) Name

func (r RuleDifferent) Name() string

func (RuleDifferent) Run

func (r RuleDifferent) Run(in RunInput) error

type RuleDomain

type RuleDomain struct{}

RuleDomain 实现了 `domain` 规则: 域名。

格式:domain md5:c411d3a07b620a12

func (RuleDomain) Message

func (r RuleDomain) Message() string

func (RuleDomain) Name

func (r RuleDomain) Name() string

func (RuleDomain) Run

func (r RuleDomain) Run(in RunInput) error

type RuleEmail

type RuleEmail struct{}

RuleEmail 实现了 `email` 规则: 邮箱地址。

格式:email md5:238fc353e79c531a

func (RuleEmail) Message

func (r RuleEmail) Message() string

func (RuleEmail) Name

func (r RuleEmail) Name() string

func (RuleEmail) Run

func (r RuleEmail) Run(in RunInput) error

type RuleEnums

type RuleEnums struct{}

RuleEnums 实现了 `enums` 规则: 值应在其常量类型的枚举值中。

格式:enums md5:e45f74add2129f75

func (RuleEnums) Message

func (r RuleEnums) Message() string

func (RuleEnums) Name

func (r RuleEnums) Name() string

func (RuleEnums) Run

func (r RuleEnums) Run(in RunInput) error

type RuleEq

type RuleEq struct{}

RuleEq 实现了 `eq` 规则: 值应与字段的值相同。

此规则的行为与 `same` 规则相同。

格式:eq:field md5:82514ba4addceb19

func (RuleEq) Message

func (r RuleEq) Message() string

func (RuleEq) Name

func (r RuleEq) Name() string

func (RuleEq) Run

func (r RuleEq) Run(in RunInput) error

type RuleFloat

type RuleFloat struct{}

RuleFloat 实现了 `float` 规则: 浮点数。需要注意的是,整数实际上也是浮点数。

格式:float md5:1de569690e034998

func (RuleFloat) Message

func (r RuleFloat) Message() string

func (RuleFloat) Name

func (r RuleFloat) Name() string

func (RuleFloat) Run

func (r RuleFloat) Run(in RunInput) error

type RuleForeach

type RuleForeach struct{}

RuleForeach 实现了 `foreach` 规则: 它告诉下一个验证使用当前值作为数组,并验证其每个元素。

格式:foreach md5:ee948d3f16a2f23d

func (RuleForeach) Message

func (r RuleForeach) Message() string

func (RuleForeach) Name

func (r RuleForeach) Name() string

func (RuleForeach) Run

func (r RuleForeach) Run(in RunInput) error

type RuleGT

type RuleGT struct{}

RuleGT 实现了 `gt` 规则: 大于 `field`。 它支持整数和浮点数。

格式:gt:field md5:3cde0145bc59e6dd

func (RuleGT) Message

func (r RuleGT) Message() string

func (RuleGT) Name

func (r RuleGT) Name() string

func (RuleGT) Run

func (r RuleGT) Run(in RunInput) error

type RuleGTE

type RuleGTE struct{}

RuleGTE 实现了 `gte` 规则: 大于或等于 `field`。 它支持整数和浮点数。

格式:gte:field md5:c3fa2ab775ef036b

func (RuleGTE) Message

func (r RuleGTE) Message() string

func (RuleGTE) Name

func (r RuleGTE) Name() string

func (RuleGTE) Run

func (r RuleGTE) Run(in RunInput) error

type RuleIn

type RuleIn struct{}

RuleIn 实现了 `in` 规则: 值应包含在:value1, value2, ...

格式:in:value1,value2,... md5:b2270542c36429af

func (RuleIn) Message

func (r RuleIn) Message() string

func (RuleIn) Name

func (r RuleIn) Name() string

func (RuleIn) Run

func (r RuleIn) Run(in RunInput) error

type RuleInteger

type RuleInteger struct{}

RuleInteger 实现了 `integer` 规则: 整数。

格式:integer md5:2d9eab0afd545045

func (RuleInteger) Message

func (r RuleInteger) Message() string

func (RuleInteger) Name

func (r RuleInteger) Name() string

func (RuleInteger) Run

func (r RuleInteger) Run(in RunInput) error

type RuleIp

type RuleIp struct{}

RuleIp 实现了`ip`规则: IPv4/IPv6。

格式:ip md5:29f0c39a26475dfa

func (RuleIp) Message

func (r RuleIp) Message() string

func (RuleIp) Name

func (r RuleIp) Name() string

func (RuleIp) Run

func (r RuleIp) Run(in RunInput) error

type RuleIpv4

type RuleIpv4 struct{}

RuleIpv4 实现了 `ipv4` 规则: 用于检查IPv4地址。

格式:ipv4 md5:db9512ff7267d5cd

func (RuleIpv4) Message

func (r RuleIpv4) Message() string

func (RuleIpv4) Name

func (r RuleIpv4) Name() string

func (RuleIpv4) Run

func (r RuleIpv4) Run(in RunInput) error

type RuleIpv6

type RuleIpv6 struct{}

RuleIpv6 实现了 `ipv6` 规则: IPv6。

格式:ipv6 md5:409b6971df3398d7

func (RuleIpv6) Message

func (r RuleIpv6) Message() string

func (RuleIpv6) Name

func (r RuleIpv6) Name() string

func (RuleIpv6) Run

func (r RuleIpv6) Run(in RunInput) error

type RuleJson

type RuleJson struct{}

RuleJson 实现了 `json` 规则: JSON。

格式:json md5:9f015465c19625e6

func (RuleJson) Message

func (r RuleJson) Message() string

func (RuleJson) Name

func (r RuleJson) Name() string

func (RuleJson) Run

func (r RuleJson) Run(in RunInput) error

type RuleLT

type RuleLT struct{}

RuleLT实现了`lt`规则: 小于`field`。 它支持整数和浮点数。

格式:lt:field md5:46a8beaf4d59f5bb

func (RuleLT) Message

func (r RuleLT) Message() string

func (RuleLT) Name

func (r RuleLT) Name() string

func (RuleLT) Run

func (r RuleLT) Run(in RunInput) error

type RuleLTE

type RuleLTE struct{}

RuleLTE 实现了 `lte` 规则: 小于或等于 `field`。 它支持整数和浮点数。

格式:lte:field md5:07792ee845b732fb

func (RuleLTE) Message

func (r RuleLTE) Message() string

func (RuleLTE) Name

func (r RuleLTE) Name() string

func (RuleLTE) Run

func (r RuleLTE) Run(in RunInput) error

type RuleLength

type RuleLength struct{}

RuleLength 实现了 `length` 规则: 字符长度在 :min 和 :max 之间。 长度是通过Unicode字符串计算的,这意味着一个中文字符或字母的长度都为1。

格式:length:min,max md5:a3bd03423a5a8b7e

func (RuleLength) Message

func (r RuleLength) Message() string

func (RuleLength) Name

func (r RuleLength) Name() string

func (RuleLength) Run

func (r RuleLength) Run(in RunInput) error

type RuleMac

type RuleMac struct{}

RuleMac 实现了 `mac` 规则: MAC 地址校验。

格式:mac md5:b1c58071a5d631fc

func (RuleMac) Message

func (r RuleMac) Message() string

func (RuleMac) Name

func (r RuleMac) Name() string

func (RuleMac) Run

func (r RuleMac) Run(in RunInput) error

type RuleMax

type RuleMax struct{}

RuleMax 实现了 `max` 规则: 小于或等于 :max。它支持整数和浮点数。

格式:max:max md5:178b1e5315ab61af

func (RuleMax) Message

func (r RuleMax) Message() string

func (RuleMax) Name

func (r RuleMax) Name() string

func (RuleMax) Run

func (r RuleMax) Run(in RunInput) error

type RuleMaxLength

type RuleMaxLength struct{}

RuleMaxLength 实现了 `max-length` 规则: 长度小于或等于 :max。长度是根据 Unicode 字符串计算的,这意味着一个中文字符或字母的长度均为 1。

格式:max-length:max md5:79ec85f367534ee2

func (RuleMaxLength) Message

func (r RuleMaxLength) Message() string

func (RuleMaxLength) Name

func (r RuleMaxLength) Name() string

func (RuleMaxLength) Run

func (r RuleMaxLength) Run(in RunInput) error

type RuleMin

type RuleMin struct{}

RuleMin 实现了`min`规则: 大于或等于`:min`。它支持整数和浮点数。

格式:min:min md5:3eacce55c94e5617

func (RuleMin) Message

func (r RuleMin) Message() string

func (RuleMin) Name

func (r RuleMin) Name() string

func (RuleMin) Run

func (r RuleMin) Run(in RunInput) error

type RuleMinLength

type RuleMinLength struct{}

RuleMinLength 实现了 `min-length` 规则: 长度等于或大于 :min。 长度计算使用的是 unicode 字符串,这意味着一个中文字符或字母的长度都为 1。

格式:min-length:min md5:565104f674e70ec7

func (RuleMinLength) Message

func (r RuleMinLength) Message() string

func (RuleMinLength) Name

func (r RuleMinLength) Name() string

func (RuleMinLength) Run

func (r RuleMinLength) Run(in RunInput) error

type RuleNotEq

type RuleNotEq struct{}

RuleNotEq 实现了 `not-eq` 规则: 值应该与字段的值不同。

格式:not-eq:字段 md5:0a6bcd6ab9b5e298

func (RuleNotEq) Message

func (r RuleNotEq) Message() string

func (RuleNotEq) Name

func (r RuleNotEq) Name() string

func (RuleNotEq) Run

func (r RuleNotEq) Run(in RunInput) error

type RuleNotIn

type RuleNotIn struct{}

RuleNotIn 实现了 "not-in" 规则: 值不应该在:value1, value2, ...

格式:not-in:value1,value2,... md5:de8746fa53d5a5b4

func (RuleNotIn) Message

func (r RuleNotIn) Message() string

func (RuleNotIn) Name

func (r RuleNotIn) Name() string

func (RuleNotIn) Run

func (r RuleNotIn) Run(in RunInput) error

type RuleNotRegex

type RuleNotRegex struct{}

RuleNotRegex 实现了 `not-regex` 规则: 值不应匹配自定义正则表达式模式。

格式:not-regex:pattern md5:ae2c4d23553ee3de

func (RuleNotRegex) Message

func (r RuleNotRegex) Message() string

func (RuleNotRegex) Name

func (r RuleNotRegex) Name() string

func (RuleNotRegex) Run

func (r RuleNotRegex) Run(in RunInput) error

type RulePassport

type RulePassport struct{}

RulePassport 实现了 `passport` 规则: 通用护照格式规则: 以字母开头,只包含数字或下划线,长度在6到18个字符之间

格式:passport md5:198c8f6806d80344

func (RulePassport) Message

func (r RulePassport) Message() string

func (RulePassport) Name

func (r RulePassport) Name() string

func (RulePassport) Run

func (r RulePassport) Run(in RunInput) error

type RulePassword

type RulePassword struct{}

RulePassword 实现了 `password` 规则: 全局密码格式规则1: 包含任何可见字符,长度在6到18之间。

格式:password md5:174006e615e50650

func (RulePassword) Message

func (r RulePassword) Message() string

func (RulePassword) Name

func (r RulePassword) Name() string

func (RulePassword) Run

func (r RulePassword) Run(in RunInput) error

type RulePassword2

type RulePassword2 struct{}

RulePassword2 实现了 `password2` 规则: 通用密码格式规则2: 必须满足密码规则1,且必须包含大小写字母和数字。

格式:password2 md5:97a3c93771b5b020

func (RulePassword2) Message

func (r RulePassword2) Message() string

func (RulePassword2) Name

func (r RulePassword2) Name() string

func (RulePassword2) Run

func (r RulePassword2) Run(in RunInput) error

type RulePassword3

type RulePassword3 struct{}

RulePassword3 实现了 `password3` 规则: 全局密码格式规则3: 必须符合密码规则1,必须包含小写字母、大写字母、数字和特殊字符。

格式:password3 md5:b62e78e30236a94a

func (RulePassword3) Message

func (r RulePassword3) Message() string

func (RulePassword3) Name

func (r RulePassword3) Name() string

func (RulePassword3) Run

func (r RulePassword3) Run(in RunInput) error

type RulePhone

type RulePhone struct{}

RulePhone 实现了 `phone` 规则:

  1. 中国移动: 134, 135, 136, 137, 138, 139, 150, 151, 152, 157, 158, 159, 182, 183, 184, 187, 188, 178(4G), 147(网络); 172

  2. 中国联通: 130, 131, 132, 155, 156, 185, 186 ,176(4G), 145(网络), 175

  3. 中国电信: 133, 153, 180, 181, 189, 177(4G)

  4. 卫星电话: 1349

  5. 虚拟运营商: 170, 173

  6. 2018年后新增: 16x, 19x

格式: 手机号码 md5:bbaf43c95c780522

func (RulePhone) Message

func (r RulePhone) Message() string

func (RulePhone) Name

func (r RulePhone) Name() string

func (RulePhone) Run

func (r RulePhone) Run(in RunInput) error

type RulePhoneLoose

type RulePhoneLoose struct{}

RulePhoneLoose implements `phone-loose` rule: Loose mobile phone number verification(宽松的手机号验证) As long as the 11 digits numbers beginning with 13, 14, 15, 16, 17, 18, 19 can pass the verification (只要满足 13、14、15、16、17、18、19开头的11位数字都可以通过验证).

Format: phone-loose

func (RulePhoneLoose) Message

func (r RulePhoneLoose) Message() string

func (RulePhoneLoose) Name

func (r RulePhoneLoose) Name() string

func (RulePhoneLoose) Run

func (r RulePhoneLoose) Run(in RunInput) error

type RulePostcode

type RulePostcode struct{}

RulePostcode 实现了 `postcode` 规则: 邮政编码数字。

格式:postcode md5:3a14b940da5b3d7b

func (RulePostcode) Message

func (r RulePostcode) Message() string

func (RulePostcode) Name

func (r RulePostcode) Name() string

func (RulePostcode) Run

func (r RulePostcode) Run(in RunInput) error

type RuleQQ

type RuleQQ struct{}

RuleQQ实现了`qq`规则: 腾讯QQ号码。

格式:qq md5:0d96642ad3034935

func (RuleQQ) Message

func (r RuleQQ) Message() string

func (RuleQQ) Name

func (r RuleQQ) Name() string

func (RuleQQ) Run

func (r RuleQQ) Run(in RunInput) error

type RuleRegex

type RuleRegex struct{}

RuleRegex 实现了 `regex` 规则: 值应该匹配自定义的正则表达式模式。

格式:regex:pattern md5:51f168fc18898499

func (RuleRegex) Message

func (r RuleRegex) Message() string

func (RuleRegex) Name

func (r RuleRegex) Name() string

func (RuleRegex) Run

func (r RuleRegex) Run(in RunInput) error

type RuleRequired

type RuleRequired struct{}

RuleRequired 实现了 `required` 规则。 格式:required md5:3ca664798f2da0f8

func (RuleRequired) Message

func (r RuleRequired) Message() string

func (RuleRequired) Name

func (r RuleRequired) Name() string

func (RuleRequired) Run

func (r RuleRequired) Run(in RunInput) error

type RuleRequiredIf

type RuleRequiredIf struct{}

RuleRequiredIf 实现了 `required-if` 规则: 如果给定的字段及其值中的任何一个相等,则为必填。

格式:required-if:field,value,... 示例:required-if:id,1,age,18 md5:fc6bf09f9de6e20b

func (RuleRequiredIf) Message

func (r RuleRequiredIf) Message() string

func (RuleRequiredIf) Name

func (r RuleRequiredIf) Name() string

func (RuleRequiredIf) Run

func (r RuleRequiredIf) Run(in RunInput) error

type RuleRequiredIfAll

type RuleRequiredIfAll struct{}

RuleRequiredIfAll 实现了 `required-if-all` 规则: 如果所有给定的字段及其值都相等,则为必填。

格式:required-if-all:field,value,... 示例:required-if-all:id,1,age,18 md5:55b9b0db38b70d0e

func (RuleRequiredIfAll) Message

func (r RuleRequiredIfAll) Message() string

func (RuleRequiredIfAll) Name

func (r RuleRequiredIfAll) Name() string

func (RuleRequiredIfAll) Run

func (r RuleRequiredIfAll) Run(in RunInput) error

type RuleRequiredUnless

type RuleRequiredUnless struct{}

RuleRequiredUnless 实现了 `required-unless` 规则: 当给定的字段及其值都不相等时,该字段是必需的。

格式:required-unless:field,value,... 示例:required-unless:id,1,age,18 md5:3492b6f7c0cf1435

func (RuleRequiredUnless) Message

func (r RuleRequiredUnless) Message() string

func (RuleRequiredUnless) Name

func (r RuleRequiredUnless) Name() string

func (RuleRequiredUnless) Run

func (r RuleRequiredUnless) Run(in RunInput) error

type RuleRequiredWith

type RuleRequiredWith struct{}

RuleRequiredWith 实现了 `required-with` 规则: 当给定的任意字段非空时,该字段是必需的。

格式:required-with:field1,field2,... 示例:required-with:id,name md5:41029b704387fd6c

func (RuleRequiredWith) Message

func (r RuleRequiredWith) Message() string

func (RuleRequiredWith) Name

func (r RuleRequiredWith) Name() string

func (RuleRequiredWith) Run

func (r RuleRequiredWith) Run(in RunInput) error

type RuleRequiredWithAll

type RuleRequiredWithAll struct{}

RuleRequiredWithAll 实现了 `required-with-all` 规则: 如果所有给定的字段都不为空,则此字段为必填。

格式:required-with-all:field1,field2,... 示例:required-with-all:id,name md5:1e341cc8965dfdc6

func (RuleRequiredWithAll) Message

func (r RuleRequiredWithAll) Message() string

func (RuleRequiredWithAll) Name

func (r RuleRequiredWithAll) Name() string

func (RuleRequiredWithAll) Run

type RuleRequiredWithout

type RuleRequiredWithout struct{}

RuleRequiredWithout 实现了 `required-without` 规则: 如果给定的任何字段为空,那么这个是必需的。

格式: required-without:field1,field2,... 示例: required-without:id,name md5:2e4a4e507f20f3a1

func (RuleRequiredWithout) Message

func (r RuleRequiredWithout) Message() string

func (RuleRequiredWithout) Name

func (r RuleRequiredWithout) Name() string

func (RuleRequiredWithout) Run

type RuleRequiredWithoutAll

type RuleRequiredWithoutAll struct{}

RuleRequiredWithoutAll 实现了 `required-without-all` 规则: 如果所有给定字段都为空,那么这个是必需的。

格式: required-without-all:field1,field2,... 示例: required-without-all:id,name md5:faeb08fb4e97c2b7

func (RuleRequiredWithoutAll) Message

func (r RuleRequiredWithoutAll) Message() string

func (RuleRequiredWithoutAll) Name

func (r RuleRequiredWithoutAll) Name() string

func (RuleRequiredWithoutAll) Run

type RuleResidentId

type RuleResidentId struct{}

RuleResidentId 实现了 `resident-id` 规则: 居民身份证号。

格式:resident-id md5:f5c8c84eb6b02680

func (RuleResidentId) Message

func (r RuleResidentId) Message() string

func (RuleResidentId) Name

func (r RuleResidentId) Name() string

func (RuleResidentId) Run

func (r RuleResidentId) Run(in RunInput) error

type RuleSame

type RuleSame struct{}

RuleSame 实现了 `same` 规则: 值应该与字段的值相同。

格式:same:field md5:433074ee67f413a5

func (RuleSame) Message

func (r RuleSame) Message() string

func (RuleSame) Name

func (r RuleSame) Name() string

func (RuleSame) Run

func (r RuleSame) Run(in RunInput) error

type RuleSize

type RuleSize struct{}

RuleSize 实现了 `size` 规则: 长度必须为 :size。 长度计算使用的是 unicode 字符串,这意味着一个中文字符或字母的长度都为 1。

格式:size:size md5:89f4bf85bbd610c6

func (RuleSize) Message

func (r RuleSize) Message() string

func (RuleSize) Name

func (r RuleSize) Name() string

func (RuleSize) Run

func (r RuleSize) Run(in RunInput) error

type RuleTelephone

type RuleTelephone struct{}

RuleTelephone 实现了 `telephone` 规则: "XXXX-XXXXXXX" "XXXX-XXXXXXXX" "XXX-XXXXXXX" "XXX-XXXXXXXX" "XXXXXXX" "XXXXXXXX"

格式:电话号码 md5:993bc2476599c2b2

func (RuleTelephone) Message

func (r RuleTelephone) Message() string

func (RuleTelephone) Name

func (r RuleTelephone) Name() string

func (RuleTelephone) Run

func (r RuleTelephone) Run(in RunInput) error

type RuleUrl

type RuleUrl struct{}

RuleUrl 实现了 `url` 规则: URL。

格式:url md5:eb24acb21d876558

func (RuleUrl) Message

func (r RuleUrl) Message() string

func (RuleUrl) Name

func (r RuleUrl) Name() string

func (RuleUrl) Run

func (r RuleUrl) Run(in RunInput) error

type RunInput

type RunInput struct {
	RuleKey     string        // RuleKey 类似于规则 "max: 6" 中的 "max". md5:b823133b6b2adfb7
	RulePattern string        // RulePattern 类似于规则 "max:6" 中的 "6". md5:1ddcd9889a484fa2
	Field       string        // Value字段的名称。 md5:25ed2e11e3b4820f
	ValueType   reflect.Type  // ValueType 指定了值的类型,可能为 nil。 md5:b1ad5cfd9a152a1d
	Value       *gvar.X结构_泛型类 // Value 指定此规则用于验证的值。 md5:29bdb57107181fe6
	Data        *gvar.X结构_泛型类 // Data 指定传递给Validator的数据。 md5:d01d5d82737671aa
	Message     string        // Message 指定此规则的自定义错误消息或配置的 i18n 消息。 md5:407649d2c7943432
	Option      RunOption     // Option 为验证规则提供额外的配置选项。 md5:37c94f95ca3b8bbc
}

type RunOption

type RunOption struct {
	CaseInsensitive bool // CaseInsensitive 表示在字符串比较时忽略大小写。 md5:46dfd02eaccd7444
}

Jump to

Keyboard shortcuts

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