Add validation error explanation for long annotations.

This commit is contained in:
Filip Grzadkowski
2015-03-23 14:31:42 +01:00
parent d0b468f4b0
commit 6bc1e2ef40
3 changed files with 4 additions and 12 deletions

View File

@@ -92,7 +92,7 @@ var _ error = &ValidationError{}
func (v *ValidationError) Error() string {
var s string
switch v.Type {
case ValidationErrorTypeRequired:
case ValidationErrorTypeRequired, ValidationErrorTypeTooLong:
s = spew.Sprintf("%s: %s", v.Field, v.Type)
default:
s = spew.Sprintf("%s: %s '%+v'", v.Field, v.Type, v.BadValue)
@@ -133,8 +133,8 @@ func NewFieldNotFound(field string, value interface{}) *ValidationError {
return &ValidationError{ValidationErrorTypeNotFound, field, value, ""}
}
func NewFieldTooLong(field string, value interface{}) *ValidationError {
return &ValidationError{ValidationErrorTypeTooLong, field, value, ""}
func NewFieldTooLong(field string, value interface{}, maxLength int) *ValidationError {
return &ValidationError{ValidationErrorTypeTooLong, field, value, fmt.Sprintf("must have at most %d characters", maxLength)}
}
type ValidationErrorList []error