- inner validators always use reflect.Value as param.
old:
// Gt check value greater dst value. only check for: int(X), uint(X), float(X)
func Gt(val any, dstVal int64) bool {
v2 new:
// Gt check value greater dst value. only check for: int(X), uint(X), float(X)
func Gt(val, dstVal any) bool {
return gt(reflect.ValueOf(val), reflect.ValueOf(dstVal))
}
// internal implements
func gt(val reflect.Value, dstVal reflect.Value) bool
- can register custom type
- use sync.Pool for optimize create Validation.
// Validation definition
type Validation struct {
// for optimize create instance. refer go-playground/validator
v *Validation
pool *sync.Pool
// ...
}
v.pool = &sync.Pool{
New: func() any {
return &Validation{
v: v,
}
},
}
- all data operate move to DataSource
type DataFace interface {
BindStruct() error
SafeVal(field string) any
...
}