MCPcopy Create free account
hub / github.com/6boris/web3-template / validate

Method validate

api/interface/web3/defi.pb.validate.go:159–217  ·  view source on GitHub ↗
(all bool)

Source from the content-addressed store, hash-verified

157}
158
159func (m *GetTokenPriceReply) validate(all bool) error {
160 if m == nil {
161 return nil
162 }
163
164 var errors []error
165
166 {
167 sorted_keys := make([]string, len(m.GetPrice()))
168 i := 0
169 for key := range m.GetPrice() {
170 sorted_keys[i] = key
171 i++
172 }
173 sort.Slice(sorted_keys, func(i, j int) bool { return sorted_keys[i] < sorted_keys[j] })
174 for _, key := range sorted_keys {
175 val := m.GetPrice()[key]
176 _ = val
177
178 // no validation rules for Price[key]
179
180 if all {
181 switch v := interface{}(val).(type) {
182 case interface{ ValidateAll() error }:
183 if err := v.ValidateAll(); err != nil {
184 errors = append(errors, GetTokenPriceReplyValidationError{
185 field: fmt.Sprintf("Price[%v]", key),
186 reason: "embedded message failed validation",
187 cause: err,
188 })
189 }
190 case interface{ Validate() error }:
191 if err := v.Validate(); err != nil {
192 errors = append(errors, GetTokenPriceReplyValidationError{
193 field: fmt.Sprintf("Price[%v]", key),
194 reason: "embedded message failed validation",
195 cause: err,
196 })
197 }
198 }
199 } else if v, ok := interface{}(val).(interface{ Validate() error }); ok {
200 if err := v.Validate(); err != nil {
201 return GetTokenPriceReplyValidationError{
202 field: fmt.Sprintf("Price[%v]", key),
203 reason: "embedded message failed validation",
204 cause: err,
205 }
206 }
207 }
208
209 }
210 }
211
212 if len(errors) > 0 {
213 return GetTokenPriceReplyMultiError(errors)
214 }
215
216 return nil

Callers 2

ValidateMethod · 0.95
ValidateAllMethod · 0.95

Calls 4

GetPriceMethod · 0.95
ValidateAllMethod · 0.45
ValidateMethod · 0.45

Tested by

no test coverage detected