blob: b9c32079b69f609ff1919ba7064527610f271576 [file] [log] [blame]
Serge Bazanskicc25bdf2018-10-25 14:02:58 +02001package govalidator
2
3import "strings"
4
5// Errors is an array of multiple errors and conforms to the error interface.
6type Errors []error
7
8// Errors returns itself.
9func (es Errors) Errors() []error {
10 return es
11}
12
13func (es Errors) Error() string {
14 var errs []string
15 for _, e := range es {
16 errs = append(errs, e.Error())
17 }
18 return strings.Join(errs, ";")
19}
20
21// Error encapsulates a name, an error and whether there's a custom error message or not.
22type Error struct {
23 Name string
24 Err error
25 CustomErrorMessageExists bool
26
27 // Validator indicates the name of the validator that failed
28 Validator string
29}
30
31func (e Error) Error() string {
32 if e.CustomErrorMessageExists {
33 return e.Err.Error()
34 }
35 return e.Name + ": " + e.Err.Error()
36}