mirror of
https://github.com/astaxie/beego.git
synced 2025-07-10 03:00:19 +00:00
add funcmap
This commit is contained in:
@ -2,6 +2,7 @@ package validation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
@ -175,3 +176,29 @@ func (v *Validation) Check(obj interface{}, checks ...Validator) *ValidationResu
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// the obj parameter must be a struct or a struct pointer
|
||||
func (v *Validation) Valid(obj interface{}) (b bool, err error) {
|
||||
t := reflect.TypeOf(obj)
|
||||
switch {
|
||||
case isStruct(t):
|
||||
case isStructPtr(t):
|
||||
t = t.Elem()
|
||||
default:
|
||||
err = fmt.Errorf("%v must be a struct or a struct pointer", obj)
|
||||
return
|
||||
}
|
||||
// tv := reflect.TypeOf(v)
|
||||
// for i := 0; i < t.NumField(); i++ {
|
||||
// f := t.Field(i)
|
||||
// var vfs []ValidFunc
|
||||
// if vfs, err = getValidFuncs(f); err != nil {
|
||||
// return
|
||||
// }
|
||||
// for _, vf := range vfs {
|
||||
// m, _ := tv.MethodByName(vf.Name)
|
||||
// m.Func
|
||||
// }
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user