1package 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	Path      []string
30}
31
32func (e Error) Error() string {
33	if e.CustomErrorMessageExists {
34		return e.Err.Error()
35	}
36
37	errName := e.Name
38	if len(e.Path) > 0 {
39		errName = strings.Join(append(e.Path, e.Name), ".")
40	}
41
42	return errName + ": " + e.Err.Error()
43}
44