Example #1
0
func GetValidatorTag(v interface{}, fn string) string {
	typ := mcore.GetType(v)
	f, e := typ.FieldByName(fn)
	if !e {
		// not found field
		logger.Warnf("not found field:%s", fn)
		return ""
	}
	return f.Tag.Get(TAG_VALIDATOR)
}
Example #2
0
// Validate
func Validate(v interface{}) map[string]string {
	m := make(map[string]string)
	typ := mcore.GetType(v)
	for i := 0; i < typ.NumField(); i++ {
		fn := typ.Field(i).Name
		logger.Debugf("Validate field:%s", fn)
		msg := ValidateField(v, fn)
		if msg == "" {
			// no error, skip
			continue
		}
		m[fn] = msg
	}
	return m
}