...
1
2
3
4 package annotations
5
6 import (
7 "bytes"
8 "errors"
9 "fmt"
10 "net"
11 "net/mail"
12 "net/url"
13 "regexp"
14 "sort"
15 "strings"
16 "time"
17 "unicode/utf8"
18
19 "google.golang.org/protobuf/types/known/anypb"
20 )
21
22
23 var (
24 _ = bytes.MinRead
25 _ = errors.New("")
26 _ = fmt.Print
27 _ = utf8.UTFMax
28 _ = (*regexp.Regexp)(nil)
29 _ = (*strings.Reader)(nil)
30 _ = net.IPv4len
31 _ = time.Duration(0)
32 _ = (*url.URL)(nil)
33 _ = (*mail.Address)(nil)
34 _ = anypb.Any{}
35 _ = sort.Sort
36 )
37
38
39
40
41 func (m *ResourceAnnotation) Validate() error {
42 return m.validate(false)
43 }
44
45
46
47
48
49 func (m *ResourceAnnotation) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *ResourceAnnotation) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60
61
62 if len(errors) > 0 {
63 return ResourceAnnotationMultiError(errors)
64 }
65
66 return nil
67 }
68
69
70
71
72 type ResourceAnnotationMultiError []error
73
74
75 func (m ResourceAnnotationMultiError) Error() string {
76 var msgs []string
77 for _, err := range m {
78 msgs = append(msgs, err.Error())
79 }
80 return strings.Join(msgs, "; ")
81 }
82
83
84 func (m ResourceAnnotationMultiError) AllErrors() []error { return m }
85
86
87
88 type ResourceAnnotationValidationError struct {
89 field string
90 reason string
91 cause error
92 key bool
93 }
94
95
96 func (e ResourceAnnotationValidationError) Field() string { return e.field }
97
98
99 func (e ResourceAnnotationValidationError) Reason() string { return e.reason }
100
101
102 func (e ResourceAnnotationValidationError) Cause() error { return e.cause }
103
104
105 func (e ResourceAnnotationValidationError) Key() bool { return e.key }
106
107
108 func (e ResourceAnnotationValidationError) ErrorName() string {
109 return "ResourceAnnotationValidationError"
110 }
111
112
113 func (e ResourceAnnotationValidationError) Error() string {
114 cause := ""
115 if e.cause != nil {
116 cause = fmt.Sprintf(" | caused by: %v", e.cause)
117 }
118
119 key := ""
120 if e.key {
121 key = "key for "
122 }
123
124 return fmt.Sprintf(
125 "invalid %sResourceAnnotation.%s: %s%s",
126 key,
127 e.field,
128 e.reason,
129 cause)
130 }
131
132 var _ error = ResourceAnnotationValidationError{}
133
134 var _ interface {
135 Field() string
136 Reason() string
137 Key() bool
138 Cause() error
139 ErrorName() string
140 } = ResourceAnnotationValidationError{}
141
View as plain text