(type_ reflect.Type)
| 34 | } |
| 35 | |
| 36 | func getOptionalInfo(type_ reflect.Type) (optionalInfo, bool) { |
| 37 | if type_ == nil { |
| 38 | return optionalInfo{}, false |
| 39 | } |
| 40 | if type_.Kind() == reflect.Ptr { |
| 41 | return optionalInfo{}, false |
| 42 | } |
| 43 | if type_.Kind() != reflect.Struct { |
| 44 | return optionalInfo{}, false |
| 45 | } |
| 46 | if type_.PkgPath() != optionalPkgPath { |
| 47 | return optionalInfo{}, false |
| 48 | } |
| 49 | name := type_.Name() |
| 50 | if name != "Optional" && !strings.HasPrefix(name, "Optional[") { |
| 51 | return optionalInfo{}, false |
| 52 | } |
| 53 | valueField, ok := type_.FieldByName("value") |
| 54 | if !ok { |
| 55 | return optionalInfo{}, false |
| 56 | } |
| 57 | hasField, ok := type_.FieldByName("has") |
| 58 | if !ok || hasField.Type.Kind() != reflect.Bool { |
| 59 | return optionalInfo{}, false |
| 60 | } |
| 61 | return optionalInfo{ |
| 62 | valueType: valueField.Type, |
| 63 | valueOffset: valueField.Offset, |
| 64 | hasOffset: hasField.Offset, |
| 65 | }, true |
| 66 | } |
| 67 | |
| 68 | func validateOptionalValueType(valueType reflect.Type) error { |
| 69 | if valueType == nil { |
no test coverage detected