...
1
2
3
4 package metricsv2
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 *MetricsServiceConfig) Validate() error {
42 return m.validate(false)
43 }
44
45
46
47
48
49 func (m *MetricsServiceConfig) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *MetricsServiceConfig) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60 if m.GetGrpcService() == nil {
61 err := MetricsServiceConfigValidationError{
62 field: "GrpcService",
63 reason: "value is required",
64 }
65 if !all {
66 return err
67 }
68 errors = append(errors, err)
69 }
70
71 if all {
72 switch v := interface{}(m.GetGrpcService()).(type) {
73 case interface{ ValidateAll() error }:
74 if err := v.ValidateAll(); err != nil {
75 errors = append(errors, MetricsServiceConfigValidationError{
76 field: "GrpcService",
77 reason: "embedded message failed validation",
78 cause: err,
79 })
80 }
81 case interface{ Validate() error }:
82 if err := v.Validate(); err != nil {
83 errors = append(errors, MetricsServiceConfigValidationError{
84 field: "GrpcService",
85 reason: "embedded message failed validation",
86 cause: err,
87 })
88 }
89 }
90 } else if v, ok := interface{}(m.GetGrpcService()).(interface{ Validate() error }); ok {
91 if err := v.Validate(); err != nil {
92 return MetricsServiceConfigValidationError{
93 field: "GrpcService",
94 reason: "embedded message failed validation",
95 cause: err,
96 }
97 }
98 }
99
100 if len(errors) > 0 {
101 return MetricsServiceConfigMultiError(errors)
102 }
103
104 return nil
105 }
106
107
108
109
110 type MetricsServiceConfigMultiError []error
111
112
113 func (m MetricsServiceConfigMultiError) Error() string {
114 var msgs []string
115 for _, err := range m {
116 msgs = append(msgs, err.Error())
117 }
118 return strings.Join(msgs, "; ")
119 }
120
121
122 func (m MetricsServiceConfigMultiError) AllErrors() []error { return m }
123
124
125
126 type MetricsServiceConfigValidationError struct {
127 field string
128 reason string
129 cause error
130 key bool
131 }
132
133
134 func (e MetricsServiceConfigValidationError) Field() string { return e.field }
135
136
137 func (e MetricsServiceConfigValidationError) Reason() string { return e.reason }
138
139
140 func (e MetricsServiceConfigValidationError) Cause() error { return e.cause }
141
142
143 func (e MetricsServiceConfigValidationError) Key() bool { return e.key }
144
145
146 func (e MetricsServiceConfigValidationError) ErrorName() string {
147 return "MetricsServiceConfigValidationError"
148 }
149
150
151 func (e MetricsServiceConfigValidationError) Error() string {
152 cause := ""
153 if e.cause != nil {
154 cause = fmt.Sprintf(" | caused by: %v", e.cause)
155 }
156
157 key := ""
158 if e.key {
159 key = "key for "
160 }
161
162 return fmt.Sprintf(
163 "invalid %sMetricsServiceConfig.%s: %s%s",
164 key,
165 e.field,
166 e.reason,
167 cause)
168 }
169
170 var _ error = MetricsServiceConfigValidationError{}
171
172 var _ interface {
173 Field() string
174 Reason() string
175 Key() bool
176 Cause() error
177 ErrorName() string
178 } = MetricsServiceConfigValidationError{}
179
View as plain text