...
1
9
10 package openapi
11
12 import (
13 "reflect"
14 )
15
16
17 func Response(code int, body interface{}) ImplResponse {
18 return ImplResponse{
19 Code: code,
20 Body: body,
21 }
22 }
23
24
25 func IsZeroValue(val interface{}) bool {
26 return val == nil || reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface())
27 }
28
29
30
31 func AssertRecurseInterfaceRequired(obj interface{}, callback func(interface{}) error) error {
32 return AssertRecurseValueRequired(reflect.ValueOf(obj), callback)
33 }
34
35
36
37 func AssertRecurseValueRequired(value reflect.Value, callback func(interface{}) error) error {
38 switch value.Kind() {
39
40 case reflect.Struct:
41 if err := callback(value.Interface()); err != nil {
42 return err
43 }
44
45
46 case reflect.Slice:
47 for i := 0; i < value.Len(); i += 1 {
48 if err := AssertRecurseValueRequired(value.Index(i), callback); err != nil {
49 return err
50 }
51 }
52 }
53 return nil
54 }
55
View as plain text