Improving an error message

This commit is contained in:
nikhiljindal
2015-06-24 15:09:43 -07:00
parent 5bd928fed0
commit 3b3ee0ed77
5 changed files with 25 additions and 18 deletions

View File

@@ -113,9 +113,13 @@ func NewFieldInvalid(field string, value interface{}, detail string) *Validation
return &ValidationError{ValidationErrorTypeInvalid, field, value, detail}
}
// NewFieldNotSupported returns a *ValidationError indicating "unsupported value"
func NewFieldNotSupported(field string, value interface{}) *ValidationError {
return &ValidationError{ValidationErrorTypeNotSupported, field, value, ""}
// NewFieldValueNotSupported returns a *ValidationError indicating "unsupported value"
func NewFieldValueNotSupported(field string, value interface{}, validValues []string) *ValidationError {
detail := ""
if validValues != nil && len(validValues) > 0 {
detail = "supported values: " + strings.Join(validValues, ", ")
}
return &ValidationError{ValidationErrorTypeNotSupported, field, value, detail}
}
// NewFieldForbidden returns a *ValidationError indicating "forbidden"