-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathvalidation_error.go
More file actions
40 lines (32 loc) · 733 Bytes
/
validation_error.go
File metadata and controls
40 lines (32 loc) · 733 Bytes
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
40
package errors
import (
"strconv"
"strings"
)
// ValidationError is an interface which IF
// it custom error types completes, then
// it can by mapped to a validation error.
//
// A validation error(s) can be given by ErrorCodeName's Validation or Err methods.
type ValidationError interface {
error
GetField() string
GetValue() any
GetReason() string
}
type ValidationErrors []ValidationError
func (errs ValidationErrors) Error() string {
var buf strings.Builder
for i, err := range errs {
buf.WriteByte('[')
buf.WriteString(strconv.Itoa(i))
buf.WriteByte(']')
buf.WriteByte(' ')
buf.WriteString(err.Error())
if i < len(errs)-1 {
buf.WriteByte(',')
buf.WriteByte(' ')
}
}
return buf.String()
}