...
1
2
3
4 package accesslogv2
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 *FileAccessLog) Validate() error {
42 return m.validate(false)
43 }
44
45
46
47
48
49 func (m *FileAccessLog) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *FileAccessLog) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60 if len(m.GetPath()) < 1 {
61 err := FileAccessLogValidationError{
62 field: "Path",
63 reason: "value length must be at least 1 bytes",
64 }
65 if !all {
66 return err
67 }
68 errors = append(errors, err)
69 }
70
71 switch v := m.AccessLogFormat.(type) {
72 case *FileAccessLog_Format:
73 if v == nil {
74 err := FileAccessLogValidationError{
75 field: "AccessLogFormat",
76 reason: "oneof value cannot be a typed-nil",
77 }
78 if !all {
79 return err
80 }
81 errors = append(errors, err)
82 }
83
84 case *FileAccessLog_JsonFormat:
85 if v == nil {
86 err := FileAccessLogValidationError{
87 field: "AccessLogFormat",
88 reason: "oneof value cannot be a typed-nil",
89 }
90 if !all {
91 return err
92 }
93 errors = append(errors, err)
94 }
95
96 if all {
97 switch v := interface{}(m.GetJsonFormat()).(type) {
98 case interface{ ValidateAll() error }:
99 if err := v.ValidateAll(); err != nil {
100 errors = append(errors, FileAccessLogValidationError{
101 field: "JsonFormat",
102 reason: "embedded message failed validation",
103 cause: err,
104 })
105 }
106 case interface{ Validate() error }:
107 if err := v.Validate(); err != nil {
108 errors = append(errors, FileAccessLogValidationError{
109 field: "JsonFormat",
110 reason: "embedded message failed validation",
111 cause: err,
112 })
113 }
114 }
115 } else if v, ok := interface{}(m.GetJsonFormat()).(interface{ Validate() error }); ok {
116 if err := v.Validate(); err != nil {
117 return FileAccessLogValidationError{
118 field: "JsonFormat",
119 reason: "embedded message failed validation",
120 cause: err,
121 }
122 }
123 }
124
125 case *FileAccessLog_TypedJsonFormat:
126 if v == nil {
127 err := FileAccessLogValidationError{
128 field: "AccessLogFormat",
129 reason: "oneof value cannot be a typed-nil",
130 }
131 if !all {
132 return err
133 }
134 errors = append(errors, err)
135 }
136
137 if all {
138 switch v := interface{}(m.GetTypedJsonFormat()).(type) {
139 case interface{ ValidateAll() error }:
140 if err := v.ValidateAll(); err != nil {
141 errors = append(errors, FileAccessLogValidationError{
142 field: "TypedJsonFormat",
143 reason: "embedded message failed validation",
144 cause: err,
145 })
146 }
147 case interface{ Validate() error }:
148 if err := v.Validate(); err != nil {
149 errors = append(errors, FileAccessLogValidationError{
150 field: "TypedJsonFormat",
151 reason: "embedded message failed validation",
152 cause: err,
153 })
154 }
155 }
156 } else if v, ok := interface{}(m.GetTypedJsonFormat()).(interface{ Validate() error }); ok {
157 if err := v.Validate(); err != nil {
158 return FileAccessLogValidationError{
159 field: "TypedJsonFormat",
160 reason: "embedded message failed validation",
161 cause: err,
162 }
163 }
164 }
165
166 default:
167 _ = v
168 }
169
170 if len(errors) > 0 {
171 return FileAccessLogMultiError(errors)
172 }
173
174 return nil
175 }
176
177
178
179
180 type FileAccessLogMultiError []error
181
182
183 func (m FileAccessLogMultiError) Error() string {
184 var msgs []string
185 for _, err := range m {
186 msgs = append(msgs, err.Error())
187 }
188 return strings.Join(msgs, "; ")
189 }
190
191
192 func (m FileAccessLogMultiError) AllErrors() []error { return m }
193
194
195
196 type FileAccessLogValidationError struct {
197 field string
198 reason string
199 cause error
200 key bool
201 }
202
203
204 func (e FileAccessLogValidationError) Field() string { return e.field }
205
206
207 func (e FileAccessLogValidationError) Reason() string { return e.reason }
208
209
210 func (e FileAccessLogValidationError) Cause() error { return e.cause }
211
212
213 func (e FileAccessLogValidationError) Key() bool { return e.key }
214
215
216 func (e FileAccessLogValidationError) ErrorName() string { return "FileAccessLogValidationError" }
217
218
219 func (e FileAccessLogValidationError) Error() string {
220 cause := ""
221 if e.cause != nil {
222 cause = fmt.Sprintf(" | caused by: %v", e.cause)
223 }
224
225 key := ""
226 if e.key {
227 key = "key for "
228 }
229
230 return fmt.Sprintf(
231 "invalid %sFileAccessLog.%s: %s%s",
232 key,
233 e.field,
234 e.reason,
235 cause)
236 }
237
238 var _ error = FileAccessLogValidationError{}
239
240 var _ interface {
241 Field() string
242 Reason() string
243 Key() bool
244 Cause() error
245 ErrorName() string
246 } = FileAccessLogValidationError{}
247
View as plain text