|
|
@ -181,7 +181,7 @@ func AssignForm(form interface{}, data map[string]interface{}) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getSize(field reflect.StructField, prefix string) string { |
|
|
|
func getRuleBody(field reflect.StructField, prefix string) string { |
|
|
|
for _, rule := range strings.Split(field.Tag.Get("binding"), ";") { |
|
|
|
for _, rule := range strings.Split(field.Tag.Get("binding"), ";") { |
|
|
|
if strings.HasPrefix(rule, prefix) { |
|
|
|
if strings.HasPrefix(rule, prefix) { |
|
|
|
return rule[len(prefix) : len(rule)-1] |
|
|
|
return rule[len(prefix) : len(rule)-1] |
|
|
@ -191,15 +191,19 @@ func getSize(field reflect.StructField, prefix string) string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetSize(field reflect.StructField) string { |
|
|
|
func GetSize(field reflect.StructField) string { |
|
|
|
return getSize(field, "Size(") |
|
|
|
return getRuleBody(field, "Size(") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetMinSize(field reflect.StructField) string { |
|
|
|
func GetMinSize(field reflect.StructField) string { |
|
|
|
return getSize(field, "MinSize(") |
|
|
|
return getRuleBody(field, "MinSize(") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetMaxSize(field reflect.StructField) string { |
|
|
|
func GetMaxSize(field reflect.StructField) string { |
|
|
|
return getSize(field, "MaxSize(") |
|
|
|
return getRuleBody(field, "MaxSize(") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetInclude(field reflect.StructField) string { |
|
|
|
|
|
|
|
return getRuleBody(field, "Include(") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: struct contains a struct
|
|
|
|
// FIXME: struct contains a struct
|
|
|
@ -260,6 +264,8 @@ func validate(errs binding.Errors, data map[string]interface{}, f Form, l macaro |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.email_error") |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.email_error") |
|
|
|
case binding.ERR_URL: |
|
|
|
case binding.ERR_URL: |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.url_error") |
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.url_error") |
|
|
|
|
|
|
|
case binding.ERR_INCLUDE: |
|
|
|
|
|
|
|
data["ErrorMsg"] = trName + l.Tr("form.include_error", GetInclude(field)) |
|
|
|
default: |
|
|
|
default: |
|
|
|
data["ErrorMsg"] = l.Tr("form.unknown_error") + " " + errs[0].Classification |
|
|
|
data["ErrorMsg"] = l.Tr("form.unknown_error") + " " + errs[0].Classification |
|
|
|
} |
|
|
|
} |
|
|
|