| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 66.67% |
| Changes | 0 | ||
| 1 | package validation |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "errors" |
||
| 5 | "fmt" |
||
| 6 | "reflect" |
||
| 7 | ) |
||
| 8 | |||
| 9 | // InapplicableConstraintError occurs when trying to use constraint on not applicable values. |
||
| 10 | // For example, if you are trying to compare slice with a number. |
||
| 11 | type InapplicableConstraintError struct { |
||
| 12 | Constraint Constraint |
||
| 13 | ValueType string |
||
| 14 | } |
||
| 15 | |||
| 16 | func (err *InapplicableConstraintError) Error() string { |
||
| 17 | return fmt.Sprintf("%s cannot be applied to %s", err.Constraint.Name(), err.ValueType) |
||
| 18 | } |
||
| 19 | |||
| 20 | func newInapplicableConstraintError(constraint Constraint, valueType string) *InapplicableConstraintError { |
||
| 21 | 1 | return &InapplicableConstraintError{ |
|
| 22 | Constraint: constraint, |
||
| 23 | ValueType: valueType, |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | // NotValidatableError occurs when validator cannot determine type by reflection or it is not supported |
||
| 28 | // by validator. |
||
| 29 | type NotValidatableError struct { |
||
| 30 | Value reflect.Value |
||
| 31 | } |
||
| 32 | |||
| 33 | func (err *NotValidatableError) Error() string { |
||
| 34 | 1 | return fmt.Sprintf("value of type %v is not validatable", err.Value.Kind()) |
|
| 35 | } |
||
| 36 | |||
| 37 | var errDefaultLanguageNotLoaded = errors.New("default language is not loaded") |
||
| 38 |