derefPointer deferences a reflect.Value that is a pointer to its underlying value. It dereferences recursively until it finds a non-pointer value. If the pointer is nil, it will be coerced to the zero value of the underlying type.
(ref reflect.Value)
| 232 | // value. It dereferences recursively until it finds a non-pointer value. If the |
| 233 | // pointer is nil, it will be coerced to the zero value of the underlying type. |
| 234 | func derefPointer(ref reflect.Value) reflect.Value { |
| 235 | if !ref.IsNil() { |
| 236 | // Grab the value the pointer references. |
| 237 | ref = ref.Elem() |
| 238 | } else { |
| 239 | // Coerce nil ptrs to zero'd values of their underlying type. |
| 240 | ref = reflect.Zero(ref.Type().Elem()) |
| 241 | } |
| 242 | |
| 243 | // Recursively deref nested pointers. |
| 244 | if ref.Kind() == reflect.Ptr { |
| 245 | return derefPointer(ref) |
| 246 | } |
| 247 | |
| 248 | return ref |
| 249 | } |
no test coverage detected