FromType returns a Nature describing a value of type "t". If "t" is nil then it returns a Nature describing an unknown value.
(t reflect.Type)
| 116 | // FromType returns a Nature describing a value of type "t". If "t" is nil then |
| 117 | // it returns a Nature describing an unknown value. |
| 118 | func (c *Cache) FromType(t reflect.Type) Nature { |
| 119 | if t == nil { |
| 120 | return Nature{} |
| 121 | } |
| 122 | var td *TypeData |
| 123 | var isInteger, isFloat bool |
| 124 | k := t.Kind() |
| 125 | switch k { |
| 126 | case reflect.Struct: |
| 127 | // c can be nil when we call the package function FromType, which uses a |
| 128 | // nil *Cache to call this method. |
| 129 | if c != nil { |
| 130 | return c.getStruct(t) |
| 131 | } |
| 132 | fallthrough |
| 133 | case reflect.Func: |
| 134 | td = new(TypeData) |
| 135 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, |
| 136 | reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: |
| 137 | _, isInteger = builtinInt[t] |
| 138 | case reflect.Float32, reflect.Float64: |
| 139 | _, isFloat = builtinFloat[t] |
| 140 | } |
| 141 | return Nature{ |
| 142 | Type: t, |
| 143 | Kind: k, |
| 144 | TypeData: td, |
| 145 | IsInteger: isInteger, |
| 146 | IsFloat: isFloat, |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | func (c *Cache) getStruct(t reflect.Type) Nature { |
| 151 | if c.structs == nil { |
no test coverage detected