37 | 37 |
"uri": isURI,
|
38 | 38 |
}
|
39 | 39 |
|
40 | |
func isURI(val interface{}, field interface{}, param string) bool {
|
|
40 |
func isURI(top interface{}, current interface{}, field interface{}, param string) bool {
|
41 | 41 |
|
42 | 42 |
st := reflect.ValueOf(field)
|
43 | 43 |
|
|
52 | 52 |
panic(fmt.Sprintf("Bad field type %T", field))
|
53 | 53 |
}
|
54 | 54 |
|
55 | |
func isURL(val interface{}, field interface{}, param string) bool {
|
|
55 |
func isURL(top interface{}, current interface{}, field interface{}, param string) bool {
|
56 | 56 |
|
57 | 57 |
st := reflect.ValueOf(field)
|
58 | 58 |
|
|
75 | 75 |
panic(fmt.Sprintf("Bad field type %T", field))
|
76 | 76 |
}
|
77 | 77 |
|
78 | |
func isEmail(val interface{}, field interface{}, param string) bool {
|
|
78 |
func isEmail(top interface{}, current interface{}, field interface{}, param string) bool {
|
79 | 79 |
|
80 | 80 |
st := reflect.ValueOf(field)
|
81 | 81 |
|
|
88 | 88 |
panic(fmt.Sprintf("Bad field type %T", field))
|
89 | 89 |
}
|
90 | 90 |
|
91 | |
func isHsla(val interface{}, field interface{}, param string) bool {
|
|
91 |
func isHsla(top interface{}, current interface{}, field interface{}, param string) bool {
|
92 | 92 |
|
93 | 93 |
st := reflect.ValueOf(field)
|
94 | 94 |
|
|
101 | 101 |
panic(fmt.Sprintf("Bad field type %T", field))
|
102 | 102 |
}
|
103 | 103 |
|
104 | |
func isHsl(val interface{}, field interface{}, param string) bool {
|
|
104 |
func isHsl(top interface{}, current interface{}, field interface{}, param string) bool {
|
105 | 105 |
|
106 | 106 |
st := reflect.ValueOf(field)
|
107 | 107 |
|
|
114 | 114 |
panic(fmt.Sprintf("Bad field type %T", field))
|
115 | 115 |
}
|
116 | 116 |
|
117 | |
func isRgba(val interface{}, field interface{}, param string) bool {
|
|
117 |
func isRgba(top interface{}, current interface{}, field interface{}, param string) bool {
|
118 | 118 |
|
119 | 119 |
st := reflect.ValueOf(field)
|
120 | 120 |
|
|
127 | 127 |
panic(fmt.Sprintf("Bad field type %T", field))
|
128 | 128 |
}
|
129 | 129 |
|
130 | |
func isRgb(val interface{}, field interface{}, param string) bool {
|
|
130 |
func isRgb(top interface{}, current interface{}, field interface{}, param string) bool {
|
131 | 131 |
|
132 | 132 |
st := reflect.ValueOf(field)
|
133 | 133 |
|
|
140 | 140 |
panic(fmt.Sprintf("Bad field type %T", field))
|
141 | 141 |
}
|
142 | 142 |
|
143 | |
func isHexcolor(val interface{}, field interface{}, param string) bool {
|
|
143 |
func isHexcolor(top interface{}, current interface{}, field interface{}, param string) bool {
|
144 | 144 |
|
145 | 145 |
st := reflect.ValueOf(field)
|
146 | 146 |
|
|
153 | 153 |
panic(fmt.Sprintf("Bad field type %T", field))
|
154 | 154 |
}
|
155 | 155 |
|
156 | |
func isHexadecimal(val interface{}, field interface{}, param string) bool {
|
|
156 |
func isHexadecimal(top interface{}, current interface{}, field interface{}, param string) bool {
|
157 | 157 |
|
158 | 158 |
st := reflect.ValueOf(field)
|
159 | 159 |
|
|
166 | 166 |
panic(fmt.Sprintf("Bad field type %T", field))
|
167 | 167 |
}
|
168 | 168 |
|
169 | |
func isNumber(val interface{}, field interface{}, param string) bool {
|
|
169 |
func isNumber(top interface{}, current interface{}, field interface{}, param string) bool {
|
170 | 170 |
|
171 | 171 |
st := reflect.ValueOf(field)
|
172 | 172 |
|
|
179 | 179 |
panic(fmt.Sprintf("Bad field type %T", field))
|
180 | 180 |
}
|
181 | 181 |
|
182 | |
func isNumeric(val interface{}, field interface{}, param string) bool {
|
|
182 |
func isNumeric(top interface{}, current interface{}, field interface{}, param string) bool {
|
183 | 183 |
|
184 | 184 |
st := reflect.ValueOf(field)
|
185 | 185 |
|
|
192 | 192 |
panic(fmt.Sprintf("Bad field type %T", field))
|
193 | 193 |
}
|
194 | 194 |
|
195 | |
func isAlphanum(val interface{}, field interface{}, param string) bool {
|
|
195 |
func isAlphanum(top interface{}, current interface{}, field interface{}, param string) bool {
|
196 | 196 |
|
197 | 197 |
st := reflect.ValueOf(field)
|
198 | 198 |
|
|
205 | 205 |
panic(fmt.Sprintf("Bad field type %T", field))
|
206 | 206 |
}
|
207 | 207 |
|
208 | |
func isAlpha(val interface{}, field interface{}, param string) bool {
|
|
208 |
func isAlpha(top interface{}, current interface{}, field interface{}, param string) bool {
|
209 | 209 |
|
210 | 210 |
st := reflect.ValueOf(field)
|
211 | 211 |
|
|
218 | 218 |
panic(fmt.Sprintf("Bad field type %T", field))
|
219 | 219 |
}
|
220 | 220 |
|
221 | |
func hasValue(val interface{}, field interface{}, param string) bool {
|
|
221 |
func hasValue(top interface{}, current interface{}, field interface{}, param string) bool {
|
222 | 222 |
|
223 | 223 |
st := reflect.ValueOf(field)
|
224 | 224 |
|
|
232 | 232 |
}
|
233 | 233 |
}
|
234 | 234 |
|
235 | |
func isGteField(val interface{}, field interface{}, param string) bool {
|
236 | |
|
237 | |
if val == nil {
|
|
235 |
func isGteField(top interface{}, current interface{}, field interface{}, param string) bool {
|
|
236 |
|
|
237 |
if current == nil {
|
238 | 238 |
panic("struct not passed for cross validation")
|
239 | 239 |
}
|
240 | 240 |
|
241 | |
topVal := reflect.ValueOf(val)
|
242 | |
|
243 | |
if topVal.Kind() == reflect.Ptr && !topVal.IsNil() {
|
244 | |
topVal = reflect.ValueOf(topVal.Elem().Interface())
|
245 | |
}
|
246 | |
|
247 | |
var topFieldVal reflect.Value
|
248 | |
|
249 | |
switch topVal.Kind() {
|
250 | |
|
251 | |
case reflect.Struct:
|
252 | |
|
253 | |
if topVal.Type() == reflect.TypeOf(time.Time{}) {
|
254 | |
topFieldVal = topVal
|
|
241 |
currentVal := reflect.ValueOf(current)
|
|
242 |
|
|
243 |
if currentVal.Kind() == reflect.Ptr && !currentVal.IsNil() {
|
|
244 |
currentVal = reflect.ValueOf(currentVal.Elem().Interface())
|
|
245 |
}
|
|
246 |
|
|
247 |
var currentFielVal reflect.Value
|
|
248 |
|
|
249 |
switch currentVal.Kind() {
|
|
250 |
|
|
251 |
case reflect.Struct:
|
|
252 |
|
|
253 |
if currentVal.Type() == reflect.TypeOf(time.Time{}) {
|
|
254 |
currentFielVal = currentVal
|
255 | 255 |
break
|
256 | 256 |
}
|
257 | 257 |
|
258 | |
f := topVal.FieldByName(param)
|
|
258 |
f := currentVal.FieldByName(param)
|
259 | 259 |
|
260 | 260 |
if f.Kind() == reflect.Invalid {
|
261 | 261 |
panic(fmt.Sprintf("Field \"%s\" not found in struct", param))
|
262 | 262 |
}
|
263 | 263 |
|
264 | |
topFieldVal = f
|
|
264 |
currentFielVal = f
|
265 | 265 |
|
266 | 266 |
default:
|
267 | 267 |
|
268 | |
topFieldVal = topVal
|
269 | |
}
|
270 | |
|
271 | |
if topFieldVal.Kind() == reflect.Ptr && !topFieldVal.IsNil() {
|
272 | |
|
273 | |
topFieldVal = reflect.ValueOf(topFieldVal.Elem().Interface())
|
|
268 |
currentFielVal = currentVal
|
|
269 |
}
|
|
270 |
|
|
271 |
if currentFielVal.Kind() == reflect.Ptr && !currentFielVal.IsNil() {
|
|
272 |
|
|
273 |
currentFielVal = reflect.ValueOf(currentFielVal.Elem().Interface())
|
274 | 274 |
}
|
275 | 275 |
|
276 | 276 |
fv := reflect.ValueOf(field)
|
|
279 | 279 |
|
280 | 280 |
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
281 | 281 |
|
282 | |
return fv.Int() >= topFieldVal.Int()
|
|
282 |
return fv.Int() >= currentFielVal.Int()
|
283 | 283 |
|
284 | 284 |
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
285 | 285 |
|
286 | |
return fv.Uint() >= topFieldVal.Uint()
|
|
286 |
return fv.Uint() >= currentFielVal.Uint()
|
287 | 287 |
|
288 | 288 |
case reflect.Float32, reflect.Float64:
|
289 | 289 |
|
290 | |
return fv.Float() >= topFieldVal.Float()
|
|
290 |
return fv.Float() >= currentFielVal.Float()
|
291 | 291 |
|
292 | 292 |
case reflect.Struct:
|
293 | 293 |
|
294 | 294 |
if fv.Type() == reflect.TypeOf(time.Time{}) {
|
295 | 295 |
|
296 | |
if topFieldVal.Type() != reflect.TypeOf(time.Time{}) {
|
|
296 |
if currentFielVal.Type() != reflect.TypeOf(time.Time{}) {
|
297 | 297 |
panic("Bad Top Level field type")
|
298 | 298 |
}
|
299 | 299 |
|
300 | |
t := topFieldVal.Interface().(time.Time)
|
|
300 |
t := currentFielVal.Interface().(time.Time)
|
301 | 301 |
fieldTime := field.(time.Time)
|
302 | 302 |
|
303 | 303 |
return fieldTime.After(t) || fieldTime.Equal(t)
|
|
307 | 307 |
panic(fmt.Sprintf("Bad field type %T", field))
|
308 | 308 |
}
|
309 | 309 |
|
310 | |
func isGtField(val interface{}, field interface{}, param string) bool {
|
311 | |
|
312 | |
if val == nil {
|
|
310 |
func isGtField(top interface{}, current interface{}, field interface{}, param string) bool {
|
|
311 |
|
|
312 |
if current == nil {
|
313 | 313 |
panic("struct not passed for cross validation")
|
314 | 314 |
}
|
315 | 315 |
|
316 | |
topVal := reflect.ValueOf(val)
|
317 | |
|
318 | |
if topVal.Kind() == reflect.Ptr && !topVal.IsNil() {
|
319 | |
topVal = reflect.ValueOf(topVal.Elem().Interface())
|
320 | |
}
|
321 | |
|
322 | |
var topFieldVal reflect.Value
|
323 | |
|
324 | |
switch topVal.Kind() {
|
325 | |
|
326 | |
case reflect.Struct:
|
327 | |
|
328 | |
if topVal.Type() == reflect.TypeOf(time.Time{}) {
|
329 | |
topFieldVal = topVal
|
|
316 |
currentVal := reflect.ValueOf(current)
|
|
317 |
|
|
318 |
if currentVal.Kind() == reflect.Ptr && !currentVal.IsNil() {
|
|
319 |
currentVal = reflect.ValueOf(currentVal.Elem().Interface())
|
|
320 |
}
|
|
321 |
|
|
322 |
var currentFielVal reflect.Value
|
|
323 |
|
|
324 |
switch currentVal.Kind() {
|
|
325 |
|
|
326 |
case reflect.Struct:
|
|
327 |
|
|
328 |
if currentVal.Type() == reflect.TypeOf(time.Time{}) {
|
|
329 |
currentFielVal = currentVal
|
330 | 330 |
break
|
331 | 331 |
}
|
332 | 332 |
|
333 | |
f := topVal.FieldByName(param)
|
|
333 |
f := currentVal.FieldByName(param)
|
334 | 334 |
|
335 | 335 |
if f.Kind() == reflect.Invalid {
|
336 | 336 |
panic(fmt.Sprintf("Field \"%s\" not found in struct", param))
|
337 | 337 |
}
|
338 | 338 |
|
339 | |
topFieldVal = f
|
|
339 |
currentFielVal = f
|
340 | 340 |
|
341 | 341 |
default:
|
342 | 342 |
|
343 | |
topFieldVal = topVal
|
344 | |
}
|
345 | |
|
346 | |
if topFieldVal.Kind() == reflect.Ptr && !topFieldVal.IsNil() {
|
347 | |
|
348 | |
topFieldVal = reflect.ValueOf(topFieldVal.Elem().Interface())
|
|
343 |
currentFielVal = currentVal
|
|
344 |
}
|
|
345 |
|
|
346 |
if currentFielVal.Kind() == reflect.Ptr && !currentFielVal.IsNil() {
|
|
347 |
|
|
348 |
currentFielVal = reflect.ValueOf(currentFielVal.Elem().Interface())
|
349 | 349 |
}
|
350 | 350 |
|
351 | 351 |
fv := reflect.ValueOf(field)
|
|
354 | 354 |
|
355 | 355 |
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
356 | 356 |
|
357 | |
return fv.Int() > topFieldVal.Int()
|
|
357 |
return fv.Int() > currentFielVal.Int()
|
358 | 358 |
|
359 | 359 |
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
360 | 360 |
|
361 | |
return fv.Uint() > topFieldVal.Uint()
|
|
361 |
return fv.Uint() > currentFielVal.Uint()
|
362 | 362 |
|
363 | 363 |
case reflect.Float32, reflect.Float64:
|
364 | 364 |
|
365 | |
return fv.Float() > topFieldVal.Float()
|
|
365 |
return fv.Float() > currentFielVal.Float()
|
366 | 366 |
|
367 | 367 |
case reflect.Struct:
|
368 | 368 |
|
369 | 369 |
if fv.Type() == reflect.TypeOf(time.Time{}) {
|
370 | 370 |
|
371 | |
if topFieldVal.Type() != reflect.TypeOf(time.Time{}) {
|
|
371 |
if currentFielVal.Type() != reflect.TypeOf(time.Time{}) {
|
372 | 372 |
panic("Bad Top Level field type")
|
373 | 373 |
}
|
374 | 374 |
|
375 | |
t := topFieldVal.Interface().(time.Time)
|
|
375 |
t := currentFielVal.Interface().(time.Time)
|
376 | 376 |
fieldTime := field.(time.Time)
|
377 | 377 |
|
378 | 378 |
return fieldTime.After(t)
|
|
382 | 382 |
panic(fmt.Sprintf("Bad field type %T", field))
|
383 | 383 |
}
|
384 | 384 |
|
385 | |
func isGte(val interface{}, field interface{}, param string) bool {
|
|
385 |
func isGte(top interface{}, current interface{}, field interface{}, param string) bool {
|
386 | 386 |
|
387 | 387 |
st := reflect.ValueOf(field)
|
388 | 388 |
|
|
427 | 427 |
panic(fmt.Sprintf("Bad field type %T", field))
|
428 | 428 |
}
|
429 | 429 |
|
430 | |
func isGt(val interface{}, field interface{}, param string) bool {
|
|
430 |
func isGt(top interface{}, current interface{}, field interface{}, param string) bool {
|
431 | 431 |
|
432 | 432 |
st := reflect.ValueOf(field)
|
433 | 433 |
|
|
471 | 471 |
// length tests whether a variable's length is equal to a given
|
472 | 472 |
// value. For strings it tests the number of characters whereas
|
473 | 473 |
// for maps and slices it tests the number of items.
|
474 | |
func hasLengthOf(val interface{}, field interface{}, param string) bool {
|
|
474 |
func hasLengthOf(top interface{}, current interface{}, field interface{}, param string) bool {
|
475 | 475 |
|
476 | 476 |
st := reflect.ValueOf(field)
|
477 | 477 |
|
|
510 | 510 |
// number. For number types, it's a simple lesser-than test; for
|
511 | 511 |
// strings it tests the number of characters whereas for maps
|
512 | 512 |
// and slices it tests the number of items.
|
513 | |
func hasMinOf(val interface{}, field interface{}, param string) bool {
|
514 | |
|
515 | |
return isGte(val, field, param)
|
516 | |
}
|
517 | |
|
518 | |
func isLteField(val interface{}, field interface{}, param string) bool {
|
519 | |
|
520 | |
if val == nil {
|
|
513 |
func hasMinOf(top interface{}, current interface{}, field interface{}, param string) bool {
|
|
514 |
|
|
515 |
return isGte(top, current, field, param)
|
|
516 |
}
|
|
517 |
|
|
518 |
func isLteField(top interface{}, current interface{}, field interface{}, param string) bool {
|
|
519 |
|
|
520 |
if current == nil {
|
521 | 521 |
panic("struct not passed for cross validation")
|
522 | 522 |
}
|
523 | 523 |
|
524 | |
topVal := reflect.ValueOf(val)
|
525 | |
|
526 | |
if topVal.Kind() == reflect.Ptr && !topVal.IsNil() {
|
527 | |
topVal = reflect.ValueOf(topVal.Elem().Interface())
|
528 | |
}
|
529 | |
|
530 | |
var topFieldVal reflect.Value
|
531 | |
|
532 | |
switch topVal.Kind() {
|
533 | |
|
534 | |
case reflect.Struct:
|
535 | |
|
536 | |
if topVal.Type() == reflect.TypeOf(time.Time{}) {
|
537 | |
topFieldVal = topVal
|
|
524 |
currentVal := reflect.ValueOf(current)
|
|
525 |
|
|
526 |
if currentVal.Kind() == reflect.Ptr && !currentVal.IsNil() {
|
|
527 |
currentVal = reflect.ValueOf(currentVal.Elem().Interface())
|
|
528 |
}
|
|
529 |
|
|
530 |
var currentFielVal reflect.Value
|
|
531 |
|
|
532 |
switch currentVal.Kind() {
|
|
533 |
|
|
534 |
case reflect.Struct:
|
|
535 |
|
|
536 |
if currentVal.Type() == reflect.TypeOf(time.Time{}) {
|
|
537 |
currentFielVal = currentVal
|
538 | 538 |
break
|
539 | 539 |
}
|
540 | 540 |
|
541 | |
f := topVal.FieldByName(param)
|
|
541 |
f := currentVal.FieldByName(param)
|
542 | 542 |
|
543 | 543 |
if f.Kind() == reflect.Invalid {
|
544 | 544 |
panic(fmt.Sprintf("Field \"%s\" not found in struct", param))
|
545 | 545 |
}
|
546 | 546 |
|
547 | |
topFieldVal = f
|
|
547 |
currentFielVal = f
|
548 | 548 |
|
549 | 549 |
default:
|
550 | 550 |
|
551 | |
topFieldVal = topVal
|
552 | |
}
|
553 | |
|
554 | |
if topFieldVal.Kind() == reflect.Ptr && !topFieldVal.IsNil() {
|
555 | |
|
556 | |
topFieldVal = reflect.ValueOf(topFieldVal.Elem().Interface())
|
|
551 |
currentFielVal = currentVal
|
|
552 |
}
|
|
553 |
|
|
554 |
if currentFielVal.Kind() == reflect.Ptr && !currentFielVal.IsNil() {
|
|
555 |
|
|
556 |
currentFielVal = reflect.ValueOf(currentFielVal.Elem().Interface())
|
557 | 557 |
}
|
558 | 558 |
|
559 | 559 |
fv := reflect.ValueOf(field)
|
|
562 | 562 |
|
563 | 563 |
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
564 | 564 |
|
565 | |
return fv.Int() <= topFieldVal.Int()
|
|
565 |
return fv.Int() <= currentFielVal.Int()
|
566 | 566 |
|
567 | 567 |
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
568 | 568 |
|
569 | |
return fv.Uint() <= topFieldVal.Uint()
|
|
569 |
return fv.Uint() <= currentFielVal.Uint()
|
570 | 570 |
|
571 | 571 |
case reflect.Float32, reflect.Float64:
|
572 | 572 |
|
573 | |
return fv.Float() <= topFieldVal.Float()
|
|
573 |
return fv.Float() <= currentFielVal.Float()
|
574 | 574 |
|
575 | 575 |
case reflect.Struct:
|
576 | 576 |
|
577 | 577 |
if fv.Type() == reflect.TypeOf(time.Time{}) {
|
578 | 578 |
|
579 | |
if topFieldVal.Type() != reflect.TypeOf(time.Time{}) {
|
|
579 |
if currentFielVal.Type() != reflect.TypeOf(time.Time{}) {
|
580 | 580 |
panic("Bad Top Level field type")
|
581 | 581 |
}
|
582 | 582 |
|
583 | |
t := topFieldVal.Interface().(time.Time)
|
|
583 |
t := currentFielVal.Interface().(time.Time)
|
584 | 584 |
fieldTime := field.(time.Time)
|
585 | 585 |
|
586 | 586 |
return fieldTime.Before(t) || fieldTime.Equal(t)
|
|
590 | 590 |
panic(fmt.Sprintf("Bad field type %T", field))
|
591 | 591 |
}
|
592 | 592 |
|
593 | |
func isLtField(val interface{}, field interface{}, param string) bool {
|
594 | |
|
595 | |
if val == nil {
|
|
593 |
func isLtField(top interface{}, current interface{}, field interface{}, param string) bool {
|
|
594 |
|
|
595 |
if current == nil {
|
596 | 596 |
panic("struct not passed for cross validation")
|
597 | 597 |
}
|
598 | 598 |
|
599 | |
topVal := reflect.ValueOf(val)
|
600 | |
|
601 | |
if topVal.Kind() == reflect.Ptr && !topVal.IsNil() {
|
602 | |
topVal = reflect.ValueOf(topVal.Elem().Interface())
|
603 | |
}
|
604 | |
|
605 | |
var topFieldVal reflect.Value
|
606 | |
|
607 | |
switch topVal.Kind() {
|
608 | |
|
609 | |
case reflect.Struct:
|
610 | |
|
611 | |
if topVal.Type() == reflect.TypeOf(time.Time{}) {
|
612 | |
topFieldVal = topVal
|
|
599 |
currentVal := reflect.ValueOf(current)
|
|
600 |
|
|
601 |
if currentVal.Kind() == reflect.Ptr && !currentVal.IsNil() {
|
|
602 |
currentVal = reflect.ValueOf(currentVal.Elem().Interface())
|
|
603 |
}
|
|
604 |
|
|
605 |
var currentFielVal reflect.Value
|
|
606 |
|
|
607 |
switch currentVal.Kind() {
|
|
608 |
|
|
609 |
case reflect.Struct:
|
|
610 |
|
|
611 |
if currentVal.Type() == reflect.TypeOf(time.Time{}) {
|
|
612 |
currentFielVal = currentVal
|
613 | 613 |
break
|
614 | 614 |
}
|
615 | 615 |
|
616 | |
f := topVal.FieldByName(param)
|
|
616 |
f := currentVal.FieldByName(param)
|
617 | 617 |
|
618 | 618 |
if f.Kind() == reflect.Invalid {
|
619 | 619 |
panic(fmt.Sprintf("Field \"%s\" not found in struct", param))
|
620 | 620 |
}
|
621 | 621 |
|
622 | |
topFieldVal = f
|
|
622 |
currentFielVal = f
|
623 | 623 |
|
624 | 624 |
default:
|
625 | 625 |
|
626 | |
topFieldVal = topVal
|
627 | |
}
|
628 | |
|
629 | |
if topFieldVal.Kind() == reflect.Ptr && !topFieldVal.IsNil() {
|
630 | |
|
631 | |
topFieldVal = reflect.ValueOf(topFieldVal.Elem().Interface())
|
|
626 |
currentFielVal = currentVal
|
|
627 |
}
|
|
628 |
|
|
629 |
if currentFielVal.Kind() == reflect.Ptr && !currentFielVal.IsNil() {
|
|
630 |
|
|
631 |
currentFielVal = reflect.ValueOf(currentFielVal.Elem().Interface())
|
632 | 632 |
}
|
633 | 633 |
|
634 | 634 |
fv := reflect.ValueOf(field)
|
|
637 | 637 |
|
638 | 638 |
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
639 | 639 |
|
640 | |
return fv.Int() < topFieldVal.Int()
|
|
640 |
return fv.Int() < currentFielVal.Int()
|
641 | 641 |
|
642 | 642 |
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
643 | 643 |
|
644 | |
return fv.Uint() < topFieldVal.Uint()
|
|
644 |
return fv.Uint() < currentFielVal.Uint()
|
645 | 645 |
|
646 | 646 |
case reflect.Float32, reflect.Float64:
|
647 | 647 |
|
648 | |
return fv.Float() < topFieldVal.Float()
|
|
648 |
return fv.Float() < currentFielVal.Float()
|
649 | 649 |
|
650 | 650 |
case reflect.Struct:
|
651 | 651 |
|
652 | 652 |
if fv.Type() == reflect.TypeOf(time.Time{}) {
|
653 | 653 |
|
654 | |
if topFieldVal.Type() != reflect.TypeOf(time.Time{}) {
|
|
654 |
if currentFielVal.Type() != reflect.TypeOf(time.Time{}) {
|
655 | 655 |
panic("Bad Top Level field type")
|
656 | 656 |
}
|
657 | 657 |
|
658 | |
t := topFieldVal.Interface().(time.Time)
|
|
658 |
t := currentFielVal.Interface().(time.Time)
|
659 | 659 |
fieldTime := field.(time.Time)
|
660 | 660 |
|
661 | 661 |
return fieldTime.Before(t)
|
|
665 | 665 |
panic(fmt.Sprintf("Bad field type %T", field))
|
666 | 666 |
}
|
667 | 667 |
|
668 | |
func isLte(val interface{}, field interface{}, param string) bool {
|
|
668 |
func isLte(top interface{}, current interface{}, field interface{}, param string) bool {
|
669 | 669 |
|
670 | 670 |
st := reflect.ValueOf(field)
|
671 | 671 |
|
|
710 | 710 |
panic(fmt.Sprintf("Bad field type %T", field))
|
711 | 711 |
}
|
712 | 712 |
|
713 | |
func isLt(val interface{}, field interface{}, param string) bool {
|
|
713 |
func isLt(top interface{}, current interface{}, field interface{}, param string) bool {
|
714 | 714 |
|
715 | 715 |
st := reflect.ValueOf(field)
|
716 | 716 |
|
|
756 | 756 |
// value. For numbers, it's a simple lesser-than test; for
|
757 | 757 |
// strings it tests the number of characters whereas for maps
|
758 | 758 |
// and slices it tests the number of items.
|
759 | |
func hasMaxOf(val interface{}, field interface{}, param string) bool {
|
760 | |
|
761 | |
return isLte(val, field, param)
|
|
759 |
func hasMaxOf(top interface{}, current interface{}, field interface{}, param string) bool {
|
|
760 |
|
|
761 |
return isLte(top, current, field, param)
|
762 | 762 |
}
|
763 | 763 |
|
764 | 764 |
// asInt retuns the parameter as a int64
|