MCPcopy Create free account
hub / github.com/imroc/req / GetPointer

Function GetPointer

internal/util/util.go:22–46  ·  view source on GitHub ↗

GetPointer return the pointer of the interface.

(v any)

Source from the content-addressed store, hash-verified

20
21// GetPointer return the pointer of the interface.
22func GetPointer(v any) any {
23 t := reflect.TypeOf(v)
24 if t.Kind() == reflect.Ptr {
25 if tt := t.Elem(); tt.Kind() == reflect.Ptr { // pointer of pointer
26 if tt.Elem().Kind() == reflect.Ptr {
27 panic("pointer of pointer of pointer is not supported")
28 }
29 el := reflect.ValueOf(v).Elem()
30 if el.IsZero() {
31 vv := reflect.New(tt.Elem())
32 el.Set(vv)
33 return vv.Interface()
34 } else {
35 return el.Interface()
36 }
37 } else {
38 if reflect.ValueOf(v).IsZero() {
39 vv := reflect.New(t.Elem())
40 return vv.Interface()
41 }
42 return v
43 }
44 }
45 return reflect.New(t).Interface()
46}
47
48// GetType return the underlying type.
49func GetType(v any) reflect.Type {

Callers 4

SetSuccessResultMethod · 0.92
SetErrorResultMethod · 0.92
UnmarshalMethod · 0.92
TestGetPointerFunction · 0.85

Calls 1

IsZeroMethod · 0.80

Tested by 1

TestGetPointerFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…