forked from jamescun/legit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
39 lines (31 loc) · 922 Bytes
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package legit
import (
"fmt"
)
// Errors contains one or more validate errors
type Errors []error
// returns string representation of the first validation error encountered
func (e Errors) Error() string {
if len(e) > 0 {
return e[0].Error()
}
return ""
}
// StructError contains the field name and message of a failed validation
type StructError struct {
Field string `json:"field"`
Message error `json:"message"`
}
// returns the string representation of the field and failed validation
func (se StructError) Error() string {
return fmt.Sprintf("%s: %s", se.Field, se.Message)
}
// SliceError contains the index and message of a failed validation
type SliceError struct {
Index int `json:"index"`
Message error `json:"message"`
}
// returns the string representation of the index and failed validation
func (se SliceError) Error() string {
return fmt.Sprintf("%d: %s", se.Index, se.Message)
}