1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-10 03:00:19 +00:00

add funcmap

This commit is contained in:
miraclesu
2013-07-24 01:20:24 +08:00
parent aba1728bc3
commit 4c6163baa0
5 changed files with 128 additions and 33 deletions

View File

@ -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
}