-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
wrapper_validations.go
44 lines (36 loc) · 1.28 KB
/
wrapper_validations.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
40
41
42
43
44
package fastshot
// DefaultValidations implements ValidationsWrapper interface and provides a default HTTP validations.
var _ ValidationsWrapper = (*DefaultValidations)(nil)
// DefaultValidations implements ValidationsWrapper interface and provides a default HTTP validations.
type DefaultValidations struct {
validations []error
}
// Unwrap will return the underlying validations
func (c *DefaultValidations) Unwrap() []error {
return c.validations
}
// Get will return the validation at the specified index
func (c *DefaultValidations) Get(index int) error {
return c.validations[index]
}
// IsEmpty will return the underlying validations
func (c *DefaultValidations) IsEmpty() bool {
return c.validations == nil || len(c.validations) == 0
}
// Count will return the number of validations
func (c *DefaultValidations) Count() int {
return len(c.validations)
}
// Add will append a new validation to the underlying validations
func (c *DefaultValidations) Add(err error) {
c.validations = append(c.validations, err)
}
// newDefaultValidations initializes a new DefaultValidations with a given validations.
func newDefaultValidations(validations []error) *DefaultValidations {
if validations == nil {
validations = make([]error, 0)
}
return &DefaultValidations{
validations: validations,
}
}