Documentation
¶
Overview ¶
Package validators holds the internal, RV-native implementations of the stateless built-in validators. They consume the cached value carrier (*fieldval.FieldValue) so the same value is not repeatedly re-reflected (reflect.ValueOf) inside each validator.
Dependency direction is one-way: root -> internal/validators -> internal/fieldval, internal/reflectx (and goutil). This package never imports the validate root package.
Index ¶
- func Between(fl *fieldval.FieldValue, minVal, maxVal any) bool
- func Enum(fl *fieldval.FieldValue, enum any) bool
- func Gt(fl *fieldval.FieldValue, dstVal any) bool
- func Gte(fl *fieldval.FieldValue, dstVal any) bool
- func IsArray(fl *fieldval.FieldValue, strict ...bool) bool
- func IsBool(fl *fieldval.FieldValue) bool
- func IsInt(fl *fieldval.FieldValue, minAndMax ...int64) bool
- func IsMap(fl *fieldval.FieldValue) bool
- func IsSlice(fl *fieldval.FieldValue) bool
- func IsString(fl *fieldval.FieldValue, minAndMaxLen ...int) bool
- func IsUint(fl *fieldval.FieldValue) bool
- func Length(fl *fieldval.FieldValue, wantLen int) bool
- func Lt(fl *fieldval.FieldValue, dstVal any) bool
- func Lte(fl *fieldval.FieldValue, dstVal any) bool
- func Max(fl *fieldval.FieldValue, dstVal any) bool
- func MaxLength(fl *fieldval.FieldValue, maxLen int) bool
- func Min(fl *fieldval.FieldValue, dstVal any) bool
- func MinLength(fl *fieldval.FieldValue, minLen int) bool
- func NotIn(fl *fieldval.FieldValue, enum any) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Between ¶
func Between(fl *fieldval.FieldValue, minVal, maxVal any) bool
Between value in the given range (inclusive). only check for: int(X), uint(X), float(X), string.
func Enum ¶
func Enum(fl *fieldval.FieldValue, enum any) bool
Enum value(int(X),string) should be in the given enum(strings, ints, uints). RV 版。
逐行对照原 Enum:复用载体缓存 RV() 经 ConvToBasicTypeRV 取基础值;字符串走 []string 包含判定,其余按 int64 走 ToInt64s/Int64sHas。原 `if X { return true } return false` 与 `return X` 行为等价,此处化简。
func Gt ¶
func Gt(fl *fieldval.FieldValue, dstVal any) bool
Gt check value greater dst value. only check for: int(X), uint(X), float(X), string.
func Gte ¶
func Gte(fl *fieldval.FieldValue, dstVal any) bool
Gte check value greater or equal dst value. only check for: int(X), uint(X), float(X), string.
func IsArray ¶
func IsArray(fl *fieldval.FieldValue, strict ...bool) bool
IsArray check value is array or slice. RV 版,支持 strict 变参。
public = if val==nil return false; reflect.Indirect(reflect.ValueOf(val)) 后判 Kind。 复现:rv := reflect.Indirect(fl.RealV()) —— fl.RealV() 已解一层,再 Indirect 一层 =匹配 public 的 ValueOf+Indirect 链(含 **T 双指针)。public 的 val==nil 早退对应 fl.Src==nil, 但注意 reflect.Call 路径里 public 实际收到 RealV().Interface()(nil 字段为 NilObject{} 非 nil), 故等价契约下不在 Src==nil 处早退,而是让 NilObject{}(struct) 自然走到 Kind 判定返回 false。
func IsBool ¶
func IsBool(fl *fieldval.FieldValue) bool
IsBool check. allow: bool, string. RV 版。
public = IndirectValue(val) 后 val.(bool) / val.(string)→strutil.ToBool。复现:对 fl.RealV()(已预解一层)再做一次 IndirectValue(=第二层),得到的动态类型断言 .(bool) /.(string)。⚠️ 用动态类型断言而非 Kind:命名类型 type MyBool bool 会判 false,与 public 的 val.(bool) 一致。
func IsInt ¶
func IsInt(fl *fieldval.FieldValue, minAndMax ...int64) bool
IsInt check, and support length check. RV 版。
原 = if val == nil return false; val = IndirectValue(val); mathutil.StrictInt(val); 然后按 minAndMax 个数做长度判定。nil 判定在 Indirect 之前(与原函数顺序一致)。
func IsMap ¶
func IsMap(fl *fieldval.FieldValue) bool
IsMap check. RV 版。
public = if val==nil return false; reflect.Indirect(reflect.ValueOf(val)).Kind()==Map。 复现同 IsArray:rv := reflect.Indirect(fl.RealV()) 后判 Kind==Map。
func IsSlice ¶
func IsSlice(fl *fieldval.FieldValue) bool
IsSlice check value is slice type. RV 版,复用载体缓存 RV() 免二次 reflect.ValueOf。
原 = if val == nil return false; reflect.Indirect(reflect.ValueOf(val)).Kind() == Slice
func IsString ¶
func IsString(fl *fieldval.FieldValue, minAndMaxLen ...int) bool
IsString check and support length check. RV 版。
原 = val = IndirectValue(val); if val == nil return false; str,isStr := val.(string); 然后按 minAndMaxLen 个数做长度判定。nil 判定在 Indirect 之后(与原函数顺序一致)。
func IsUint ¶
func IsUint(fl *fieldval.FieldValue) bool
IsUint check, allow: intX, uintX, string. RV 版。
public 无 indirection,对 fl.RealV().Interface() 直接做 type-switch。RealV 已完成 reflect.Call 路径的那一次预解引用,这里不再二次解引用 —— 与 public(RealV().Interface()) 逐分支一致。注意用动态类型 type-switch(命名类型 type MyInt int 会落到 int case)。
func Length ¶
func Length(fl *fieldval.FieldValue, wantLen int) bool
Length equal check for string, array, slice, map. RV 版。
func Lt ¶
func Lt(fl *fieldval.FieldValue, dstVal any) bool
Lt less than dst value. only check for: int(X), uint(X), float(X).
func Lte ¶
func Lte(fl *fieldval.FieldValue, dstVal any) bool
Lte less than or equal dst value. only check for: int(X), uint(X), float(X).
func Max ¶
func Max(fl *fieldval.FieldValue, dstVal any) bool
Max less than or equal dst value, alias Lte(). only check for: int(X), uint(X), float(X).
func MaxLength ¶
func MaxLength(fl *fieldval.FieldValue, maxLen int) bool
MaxLength check for string, array, slice, map. RV 版。
func Min ¶
func Min(fl *fieldval.FieldValue, dstVal any) bool
Min check value greater or equal dst value, alias Gte(). only check for: int(X), uint(X), float(X), string.
Types ¶
This section is empty.