2015-11-19 16:32:18 +00:00
|
|
|
package govalidator
|
|
|
|
|
2016-06-01 14:24:48 +00:00
|
|
|
// Errors is an array of multiple errors and conforms to the error interface.
|
2015-11-19 16:32:18 +00:00
|
|
|
type Errors []error
|
|
|
|
|
2016-06-01 14:24:48 +00:00
|
|
|
// Errors returns itself.
|
2015-11-19 16:32:18 +00:00
|
|
|
func (es Errors) Errors() []error {
|
|
|
|
return es
|
|
|
|
}
|
|
|
|
|
|
|
|
func (es Errors) Error() string {
|
|
|
|
var err string
|
|
|
|
for _, e := range es {
|
|
|
|
err += e.Error() + ";"
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-06-01 14:24:48 +00:00
|
|
|
// Error encapsulates a name, an error and whether there's a custom error message or not.
|
2015-11-19 16:32:18 +00:00
|
|
|
type Error struct {
|
2016-04-26 00:18:04 +00:00
|
|
|
Name string
|
|
|
|
Err error
|
|
|
|
CustomErrorMessageExists bool
|
2015-11-19 16:32:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e Error) Error() string {
|
2016-04-26 00:18:04 +00:00
|
|
|
if e.CustomErrorMessageExists {
|
|
|
|
return e.Err.Error()
|
|
|
|
}
|
2016-06-01 14:24:48 +00:00
|
|
|
return e.Name + ": " + e.Err.Error()
|
2015-11-19 16:32:18 +00:00
|
|
|
}
|