ExtractPointer returns the underlying value by the given interface type Play: https://go.dev/play/p/D7HFjeWU2ZP
(value any)
| 64 | // ExtractPointer returns the underlying value by the given interface type |
| 65 | // Play: https://go.dev/play/p/D7HFjeWU2ZP |
| 66 | func ExtractPointer(value any) any { |
| 67 | if IsNil(value) { |
| 68 | return value |
| 69 | } |
| 70 | t := reflect.TypeOf(value) |
| 71 | v := reflect.ValueOf(value) |
| 72 | |
| 73 | if t.Kind() != reflect.Pointer { |
| 74 | return value |
| 75 | } |
| 76 | |
| 77 | if v.Elem().IsValid() { |
| 78 | return ExtractPointer(v.Elem().Interface()) |
| 79 | } |
| 80 | |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | // IsNil returns true if the given interface is nil or the underlying value is nil. |
| 85 | func IsNil(i interface{}) bool { |
searching dependent graphs…